public class TestSwitch {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份");
int yy = scan.nextInt();
System.out.println("请输入一个月份");
int MM = scan.nextInt();
System.out.println("请输入一个日期");
int dd =scan.nextInt();
int num=0;
boolean isLeap =((yy%400==0)||(yy%4==0&&yy%100!=0));
switch(MM){
case 12:
num+=30;
case 11:
num+=31;
case 10:
num+=30;
case 9:
num+=31;
case 8:
num+=31;
case 7:
num+=30;
case 6:
num+=31;
case 5:
num+=30;
case 4:
num+=31;
case 3:
if(isLeap){
num+=29;
}else{
num+=28;
}
case 2:
num+=31;
case 1:
num+=dd;
}
System.out.println(yy+"年"+MM+"月"+dd+"日是第一年中第"+num+"天");
}
}
java基础:输入一个年份,月份,日期,计算当前日期是一年中的第几天
原文:https://www.cnblogs.com/C33baby/p/12780648.html