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 + "天");
}
}

posted on 2018-04-26 21:03  HopeWu  阅读(313)  评论(0编辑  收藏  举报

导航