`
thecloud
  • 浏览: 879477 次
文章分类
社区版块
存档分类
最新评论

输入年月日,算出那天是当年的第几天

 
阅读更多

思路很简单,大家一看就懂~

import java.util.*;
class WhichDay 
{
	static void whichday(String date)
	{
		int days=0;
		String[] str1=date.split("年");
		int year=new Integer(str1[0]);
		String[] str2=str1[1].split("月");
		int month=new Integer(str2[0]);
		String[] str3=str2[1].split("日");
		int day=new Integer(str3[0]);
		int[] mdays=new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
		if(year%4==0&&year%100!=0|year%400==0)
		mdays[2]=29;
		for(int i=1;i<=month-1;i++)
			days+=mdays[i];
		days+=day;
		System.out.println(days);
	}
	public static void main(String[] args) 
	{
		Scanner sc=new Scanner(System.in);
		String date=sc.next();
		whichday(date);
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics