我们输入几月几号计算出当天是今年的第几天
代码如下:
public class C_201_02_06天数计算 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入月份");
int month = scanner.nextInt();
System.out.println("请输入几号");
int day = scanner.nextInt();
int days = day;//当月的天数
switch (month-1){
case 11:days +=30;
case 10:days +=31;
case 9:days +=30;
case 8:days +=31;
case 7:days +=31;
case 6:days +=30;
case 5:days +=31;
case 4:days +=30;
case 3:days +=31;
case 2:days +=28;
case 1:days +=31;
}
System.out.println(days);
}
}
运行结果: