java 输入日期某年某月某日 查是第几天的程序问题?

2024-11-26 06:50:53
推荐回答(2个)
回答1:

public class Sun9 { public static void main(String[] args) { Scanner in =new Scanner(System.in); System.out.print("请输入年份:"); int year =in.nextInt(); System.out.print("请输入月份:"); int mouth = in.nextInt(); System.out.print("请输入几号:"); int day = in.nextInt(); int maxday=0; for(int i=1;i12) { year++; mouth-=12; } if(mouth<1) { year--; mouth=12-mouth; } switch(i){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: maxday+=31; break; case 4: case 6: case 9: case 11: maxday+=30; break; case 2: maxday+=28; break; default: System.out.println("输入月份错误!"); } } if((mouth)>2&&((year%4==0)&&year%100!=0)||(year%400==0)){ maxday++; } maxday+=day; System.out.println("此天是第:"+maxday+"天"); } }
希望采纳

回答2:

当你输入13月时,你的for(int i=1;i