JAVA经典算法(十四)

题目:输入某年某月某日,判断这一天是这一年的第几天?  

先给大家科普一下:

闰年是公历中的名词。闰年分为普通闰年和世纪闰年。

普通闰年:公历年份是4的倍数的,且不是100的倍数,为闰年。(如2004年就是闰年);

世纪闰年:公历年份是整百数的,必须是400的倍数才是世纪闰年(如1900年不是世纪闰年,2000年是世纪闰年);

公历中只分闰年和平年,平年有365天,而闰年有366天(2月中多一天)

package cn.ls.lanqiao;

import java.util.*;

public class Test14 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("请分别输入所要查询的年月日:");
		int year = sc.nextInt();
		int month = sc.nextInt();
		int days = sc.nextInt();
		int[] list = { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
		int count = 0;
		if (month == 1) {
			count = days;
		}
		if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
			if (month > 1 && month < 13) {
				count = list[month - 2] + days;
			}
		} else {
			if (month > 1 && month < 13) {
				count = list[month - 2] + days - 1;
			}
		}
		System.out.print("这是该年的第" + count + "天");
	}

}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值