帮忙看下,谢谢
import java.util.*;public class Demo
{
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_MONTH);
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_MONTH);
}
while(d.get(Calendar.MONTH)==month);
if(weekday!=Calendar.SUNDAY)
System.out.println();
}
}
不知道问题出在哪里,请帮帮忙!
----------------解决方案--------------------------------------------------------
程序可以运行,你指的是输出格式有问题吧
----------------解决方案--------------------------------------------------------
回复 楼主 anhuizxw
do{}里面最后一句改成:weekday=d.get(Calendar.DAY_OF_WEEK);看看是不是你想要的结果!
----------------解决方案--------------------------------------------------------
if(day==today)改为equals 判断试试
----------------解决方案--------------------------------------------------------
import java.util.*;
public class Demo
{
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\tMon\tTue\tWed\tThu\tFri\tSat");
for(int i=Calendar.SUNDAY;i<weekday;i++)
System.out.print("\t");
do
{
int day=d.get(Calendar.DAY_OF_MONTH);
System.out.printf("%3d",day);
if(day==today)
System.out.print("*\t");
else
System.out.print("\t");
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();
}
}
----------------解决方案--------------------------------------------------------
更改过的。你看看。qq截图是运行后的效果图。
----------------解决方案--------------------------------------------------------