zoukankan      html  css  js  c++  java
  • 分支-13. 计算天数(15)

    版权声明: https://blog.csdn.net/oFengWuYu1/article/details/27113033

    本题要求编敲代码计算某年某月某日是该年中的第几天。

    输入格式:

    输入在一行中依照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。

    闰年的2月有29天。

    输出格式:

    在一行输出日期是该年中的第几天。

    输入例子1:
    2009/03/02
    
    输出例子1:
    61
    
    输入例子2:
    2000/03/02
    
    输出例子2:

    62

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner cin = new Scanner(System.in);
    		String str = cin.nextLine();
    		String[] strs = str.split("/");
    		int year = Integer.parseInt(strs[0]);
    		int month = Integer.parseInt(strs[1]);
    		int day = Integer.parseInt(strs[2]);
    		int[] months = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    		if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
    			months[1] = 29;
    		}
    		int result = 0;
    		for (int i = 0; i < month - 1; i++) {
    			result += months[i];
    		}
    		result += day;
    		System.out.print(result);
    	}
    }
    


    
                
查看全文
  • 相关阅读:
    90%的人不知道Python炫技的7个骚操作
    想查看微信好友撤回的消息?Python帮你搞定
    Python统计长字符串中字符频次【入门必学】
    用什么库写Python命令行程序?80%的人都用错了
    Python文件操作方法,看这篇就足够
    Python单例模式最佳实战【入门必学】
    学Python,连yield关键字你都不会用就太失败了吧?
    编译原理--引论(四)
    编译原理--引论(三)
    2012年英语一小作文
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10716327.html
  • Copyright © 2011-2022 走看看