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);
    	}
    }
    


    
                
查看全文
  • 相关阅读:
    代码转换为html显示
    subprocess实时获取结果和捕获错误
    centos7开放端口和防火墙设置
    Inside The C++ Object Model(一)
    知其所以然(以算法学习为例)
    sql语法
    DLL断点调试
    我的算法学习之路
    算法系列之一
    cocos2d-x游戏引擎核心(3.x)----事件分发机制之事件从(android,ios,desktop)系统传到cocos2dx的过程浅析
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10716327.html
  • Copyright © 2011-2022 走看看