import java.util.*;
public class CalendarTest
{
public static void main(String[] args)
{
GregorianCalendar d=new GregorianCalendar();
int today=d.get(Calendar.DAY_OF_MONTH);
int month=d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH,1);
int weekday=d.get(Calendar.DAY_OF_WEEK);
System.out.println("Sun Mon Tue Wed Thu Fri Sat");
for(int i=Calendar.SUNDAY;i<weekday;i++)
System.out.print(" ");
do
{
int day=d.get(Calendar.DAY_OF_MONTH);
System.out.printf("%3d",day);
if(day==today)
System.out.print("*");
else
System.out.print(" ");
if(weekday==Calendar.SATURDAY)
System.out.println();
d.add(Calendar.DAY_OF_MONTH,1);
weekday=d.get(Calendar.DAY_OF_WEEK);
}
while(d.get(Calendar.MONTH)==month);
if(weekday!=Calendar.SUNDAY)
System.out.println();
}
}
书上的一段代码....输出当月的日历形式,想问下System.out.printf("%3d",day);这条语句为什么在Eclipse3.2会报错??
~~~类型 PrintStream 中的方法 printf(String, Object[])对于参数(String, int)不适用~~~
而在BLUEJ上却能运行??还有就是int weekday=d.get(Calendar.DAY_OF_WEEK);输出weekday输出为2(今天星期5),而在输出日历表的时候却是正确的显示(在星期5标了*)...
public class CalendarTest
{
public static void main(String[] args)
{
GregorianCalendar d=new GregorianCalendar();
int today=d.get(Calendar.DAY_OF_MONTH);
int month=d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH,1);
int weekday=d.get(Calendar.DAY_OF_WEEK);
System.out.println("Sun Mon Tue Wed Thu Fri Sat");
for(int i=Calendar.SUNDAY;i<weekday;i++)
System.out.print(" ");
do
{
int day=d.get(Calendar.DAY_OF_MONTH);
System.out.printf("%3d",day);
if(day==today)
System.out.print("*");
else
System.out.print(" ");
if(weekday==Calendar.SATURDAY)
System.out.println();
d.add(Calendar.DAY_OF_MONTH,1);
weekday=d.get(Calendar.DAY_OF_WEEK);
}
while(d.get(Calendar.MONTH)==month);
if(weekday!=Calendar.SUNDAY)
System.out.println();
}
}
书上的一段代码....输出当月的日历形式,想问下System.out.printf("%3d",day);这条语句为什么在Eclipse3.2会报错??
~~~类型 PrintStream 中的方法 printf(String, Object[])对于参数(String, int)不适用~~~
而在BLUEJ上却能运行??还有就是int weekday=d.get(Calendar.DAY_OF_WEEK);输出weekday输出为2(今天星期5),而在输出日历表的时候却是正确的显示(在星期5标了*)...
1 2 3 4 5 6
7 8 9 10 11 12* 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 这个是我运行出的结果哈!你看看嘛
1 2 3 4 5 6
7 8 9 10 11 12* 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
窗口/设定/java/已安装的JRE 在这里追加1.5的JRE
窗口/设定/java/编译器 在这里选择版本
1 2 3 4 5 6
7 8 9 10 11 12* 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13*
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31没有任何问题