妙用switch 计算几天是 一年的第几天

来源:互联网 发布:2017会计电算化软件 编辑:程序博客网 时间:2024/05/06 06:39
import java.util.Scanner;public class Demo{    public static void main(String[] args){         Scanner input = new Scanner(System.in);         System.out.print("请输入年份");         int year = input.nextInt();         System.out.print("请输入月份");         int month = input.nextInt();         System.out.print("请输入几号");         int day = input.nextInt();                  int count = 0;        switch(month){             case 12:  count += 30;             case 11:  count += 31;             case 10:  count += 30;             case 9:   count += 31;             case 8:   count += 31;             case 7:   count += 30;             case 6:   count += 31;             case 5:   count += 30;             case 4:   count += 31;             case 3:   count += 28;             case 2:   count += 31;             case 1:   count += day;        }        System.out.print("今天是一年中的第"+count+"天");    } }

0 0
原创粉丝点击