码迷,mamicode.com
首页 > 编程语言 > 详细

java 练习题5

时间:2016-05-16 17:35:06      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

//题目:输入某年某月某日,判断这一天是这一年的第几天?
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入年份");
        int n =sc.nextInt();
        System.out.println("请输入年份");
        int y =sc.nextInt();
        System.out.println("请输入年份");
        int r=sc.nextInt();
        int sum=0;
        int eryue=28;
        if((n%4==0 && n%100!=0) || n%400==0)
        {
            eryue=29;
        }
        switch(y)
        {
        case 1:
            sum=r;
            break;
        case 2:
            sum = 31+eryue+r;
            break;
        case 3:
            sum = 31+eryue+31+r;
            break;
        case 4:
            sum = 31+eryue+31+30+r;
            break;
        case 5:
            sum = 31+eryue+31+30+r;
            break;
        case 6:
            sum = 31+eryue+31+30+31+r;
            break;
        case 7:
            sum = 31+eryue+31+30+31+30+r;
            break;
        case 8:
            sum = 31+eryue+31+30+31+30+31+r;
            break;
        case 9:
            sum = 31+eryue+31+30+31+30+31+31+r;
            break;
        case 10:
            sum = 31+eryue+31+30+31+30+31+31+30+r;
            break;
        case 11:
            sum = 31+eryue+31+30+31+30+31+31+30+31+r;
            break;
        case 12:
             sum = 31+eryue+31+30+31+30+31+31+30+31+30+r;
            break;
        }
        System.out.println(n+" 年 "+y+" 月 " +r + "号是"+n+"年的第"+sum+"天");

技术分享技术分享

java 练习题5

标签:

原文地址:http://www.cnblogs.com/jskbk/p/5498565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!