关于java中输出日历
publicclassMyDate{publicstaticvoidmain(String[]args){Scannerscan=newScanner(System.in...
public class MyDate {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("请输入年份:");
int year=scan.nextInt();
System.out.println("请输入月份:");
int month=scan.nextInt();
int day=1;
Calendar c=Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);
System.out.print("星期日\t");
System.out.print("星期一\t");
System.out.print("星期二\t");
System.out.print("星期三\t");
System.out.print("星期四\t");
System.out.print("星期五\t");
System.out.println("星期六\t");
int weekday=c.get(Calendar.DAY_OF_WEEK)-1;
int count=0;
for (int i = 0; i < weekday; i++,count++) {
System.out.print("**\t");
}
int maxday=c.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 1; i <= maxday; i++,count++) {
if(count%7==0)
{
System.out.println();
count=0;
}
System.out.print(i+"\t");
}
}
}
上述程序中:
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);
和Calendar c=Calendar.getInstance();语句应该怎么理解??? 展开
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("请输入年份:");
int year=scan.nextInt();
System.out.println("请输入月份:");
int month=scan.nextInt();
int day=1;
Calendar c=Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);
System.out.print("星期日\t");
System.out.print("星期一\t");
System.out.print("星期二\t");
System.out.print("星期三\t");
System.out.print("星期四\t");
System.out.print("星期五\t");
System.out.println("星期六\t");
int weekday=c.get(Calendar.DAY_OF_WEEK)-1;
int count=0;
for (int i = 0; i < weekday; i++,count++) {
System.out.print("**\t");
}
int maxday=c.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 1; i <= maxday; i++,count++) {
if(count%7==0)
{
System.out.println();
count=0;
}
System.out.print(i+"\t");
}
}
}
上述程序中:
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);
和Calendar c=Calendar.getInstance();语句应该怎么理解??? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询