[size=large]import java.util.Scanner;
public class CalTest
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("请输入年份:");
int year=sc.nextInt();
System.out.println("请输入月份:");
int month=sc.nextInt();
int totalDays=0;
int days=0;
for(int i=1900;i<year;i++){
if((i%4==0 && i%100!=0)||i%400==0){
totalDays+=366;
}else{
totalDays+=365;
}
}
for (int i=1;i<=month;i++)
{
if(i==2){
if((year%4==0 && year%100!=0)||year%400==0)
{
days=29;
}else{
days=28;
}
}else if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12){
days=31;
}
else{
days=30;
}
if(i!=month){
totalDays+=days;
}
}
int firstDay=(totalDays%7)+1;
System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日");
for(int i=0;i<firstDay-1;i++){
System.out.print("\t");
}
for(int j=1;j<=days;j++){
System.out.print(j+"\t");
if((firstDay+j-1)%7==0){
System.out.println();
}
}
}
}
[/size]
public class CalTest
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("请输入年份:");
int year=sc.nextInt();
System.out.println("请输入月份:");
int month=sc.nextInt();
int totalDays=0;
int days=0;
for(int i=1900;i<year;i++){
if((i%4==0 && i%100!=0)||i%400==0){
totalDays+=366;
}else{
totalDays+=365;
}
}
for (int i=1;i<=month;i++)
{
if(i==2){
if((year%4==0 && year%100!=0)||year%400==0)
{
days=29;
}else{
days=28;
}
}else if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12){
days=31;
}
else{
days=30;
}
if(i!=month){
totalDays+=days;
}
}
int firstDay=(totalDays%7)+1;
System.out.println("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日");
for(int i=0;i<firstDay-1;i++){
System.out.print("\t");
}
for(int j=1;j<=days;j++){
System.out.print(j+"\t");
if((firstDay+j-1)%7==0){
System.out.println();
}
}
}
}
[/size]