java中switch用法,输出第几天
import java.util.Scanner;
public class month{
public static void main(String [] args){
Scanner scanner=new Scanner(System.in);
/*
输入month=? day=?
输出第几天
*/
System.out.print("month:");
int month = scanner.nextInt();
System.out.print("day:");
int day = scanner.nextInt();
int days = 0;
switch (month){
case 12:days += 30;
case 11:days += 31;
case 10:days += 30;
case 9:days += 31;
case 8:days += 31;
case 7:days += 30;
case 6:days += 31;
case 5:days += 30;
case 4:days += 31;
case 3:days += 28;
case 2:days += 31;
case 1:days += day;
}
System.out.println("第" + days + "天");
}
}