输入年月,输出该月份的日历页
程序员文章站
2022-05-07 21:55:04
...
输入输出说明:
import java.util.Calendar;
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Calendar cal = Calendar.getInstance();
Scanner scan = new Scanner(System.in);
int year,m,days = 0;
year = scan.nextInt();
m = scan.nextInt();
cal.set(year,m-1,1);
int day = cal.get(Calendar.DAY_OF_WEEK)-1;
int j = m;
switch(j){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
days=31;
break;
case 2:
if((year%100!=0) && (year%4==0) || (year%400==0))
days = 29;
else
days=28;
break;
default:
days=30;
break;
}
int ii = 1;
for(;ii<=day;ii++)
System.out.print(" ");
for(int k=1;ii<=day+days;ii++){
System.out.printf("%5d",k++);
if(ii%7==0)
System.out.println();
}
}
}
上一篇: FullCalendar
下一篇: Drools 将DSLR转化为DRL
推荐阅读