/**
* 题目:输入某年某月某日,判断这一天是这一年的第几天?
* 时间:2015年7月29日08:31:58
* 文件:Lianxi14.java
* 作者:cutter_point
*/
package bishi.zuixin50.t2015729;
import java.util.*;
public class Lianxi14
{
public static void main(String [] args)
{
//键盘输入年月日
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
int month = sc.nextInt();
int day = sc.nextInt();
getDays(year, month, day);
}
public static void getDays(int year, int month, int day)
{
//首先我们判断是不是闰年
int y = year % 4;
int y2 = year % 400;
//判断月份,这个是31天的
List<Integer> m1 = new ArrayList<Integer>(Arrays.asList(1, 3, 5, 7, 8, 10, 12));
//30天的
List<Integer> m2 = new ArrayList<Integer>(Arrays.asList(4, 6, 9, 11));
int days = 0;
//能被整除是闰年,闰年二月份29天
for(int i = 1; i <= month; ++i)
{
if(m1.contains(i))
{
if(i != month)
{
days += 31;
}
else
{
days += day;
}
}
else if(m2.contains(i))
{
if(i != month)
{
days += 30;
}
else
{
days += day;
}
}
else
{
if(y == 0 || y2 == 0)
{
if(i != month)
{
days += 29;//二月是29天
}
else
{
days += day;
}
}
else
{
if(i != month)
{
//不是闰年
days += 28;
}
else
{
days += day;
}
}
}
}/*for(int i = 1; i <= month; ++i)*/
System.out.println("这是一年中的第:" + days + "天");
}
}
【笔试】14、判断这一天是这一年的第几天
最新推荐文章于 2024-04-24 23:01:09 发布