能不能告诉我哪里错了

import java.util.*;




public class Example3223 {

public static void main(String[] args) throws Exception{

Scanner S1=new Scanner(System.in);

System.out.println("请输入你想知道月历的年数(格式:yyyy):");

int year=S1.nextInt();

if(year<1){

System.out.println("输入的年份不能小于1!");

return;

}

System.out.println("请输入你想知道月历的月数(格式:mm):");

int month=S1.nextInt();

if(month<1||month>12){

System.out.println("输入的月份不能小于1和大于12!");

return;

}

System.out.println("这是"+year+"年"+month+"月的月历:");

System.out.println("***********************************************************");

System.out.println("日\t一\t二\t三\t四\t五\t六");

Example3223 y=new Example3223();

y.print(year,month);

}

public int getWeek(int year,int month){

Date date=new Date();

date.setYear(year);

date.setMonth(month);

Calendar calendar=Calendar.getInstance();

calendar.setTime(date);

return calendar.get(calendar.DAY_OF_WEEK);

}

public void print(int year,int month){

int day=getDay(year,month);

int week=getWeek(year,month);

for(int i=0;i<=week;i++){

System.out.print(" \t");

}

for(int j=1;j<=day;j++){

if((j+week)%7==0){

System.out.println();

}

System.out.print(j+"\t");

}

}

public int getDay(int year,int month){

   switch(month){

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

return 31;

case 4:

case 6:

case 9:

case 11:

return 30;

case 2:

if(isLeapYear(year))return 29;

else return 28;

}

return 0;

}

public static boolean isLeapYear(int y){

return((y%4==0&&y%100!=0)||y%400==0);

}

}


诺大大
浏览 1229回答 1
1回答

qq_岁月静好与君语_0

main方法里面不需要return,实在要跳出方法可以采用System.exit(1);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java