题目:
随机输入month、day,求总天数。
代码:
package scan;
import java.util.Scanner;
public class Yy{
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入month:");
int month = scan.nextInt();
System.out.println("请输入day:");
int day = scan.nextInt();
int sumdays = 0;
switch (month) {
case 12 :
sumdays += 30;
case 11 :
sumdays += 31;
case 10 :
sumdays += 30;
case 9 :
sumdays += 31;
case 8 :
sumdays += 31;
case 7 :
sumdays += 30;
case 6 :
sumdays += 31;
case 5 :
sumdays += 30;
case 4 :
sumdays += 31;
case 3 :
sumdays += 30;
case 2 :
sumdays += 28;
case 1 :
sumdays += day;
}
System.out.println("北京时间" + month + "月" + day + "日是第" + sumdays + "天");
}
}