Loading

java编程练习

package HomeWork05;
import java.util.Scanner;
public class HomeWork05 {
public static void main(String[]args){
    Scanner sc =new Scanner(System.in);
    System.out.print("年");
    int year=sc.nextInt();
    System.out.print("月");
    int month=sc.nextInt();
    System.out.print("日");
    int day=sc.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:
            if((year%4==0&&year%100!=0)||(year%400==0)){
                days+=29;
                }
            else{
                days+=28;
                }
        case 2:days+=31;
        case 1:days+=day;
    }
        System.out.print("第" + days + "天");
}
}

这个程序是复制别人过来的,写的好的地方是充分利用了switch,case的特性,很有想法;
原作者地址:https://www.cnblogs.com/soulsjie/p/7501097.html

posted @ 2019-04-24 11:35  以南为客  阅读(166)  评论(0编辑  收藏  举报