import java.util.Scanner;
public class LeapYear{
public static void main(String[] args){
System.out.println("Please enter a year greater than 1582.");
Scanner scan=new Scanner(System.in);
int year=scan.nextInt();
int month=2,day=29;
if(year>=1582){
if(isLeapYear(year)){
System.out.println("\n"+year+" is leap year");
Zellers(year,month,day);
}
else{
System.out.println("\n"+year+" is not leap year");
}
}
else{
System.out.println("\nThe year that entered is out of range.");
}
}
public static boolean isLeapYear(int year){
if (year%4==0 && year%100!=0){
return true;
}
else{
if (year%400==0)
return true;
}
return false;
}
public static void Zellers(int year,int month,int day){
int LeapFactor,DayNumber,StartMonth,StartYear;
if (month<3)
{
StartMonth=0;
StartYear=year-1;
}
else
{
StartMonth = (int) (0.4*month+2.3);
StartYear = year;
}
LeapFactor =(StartYear/4)-(StartYear/100)+(StartYear/400);
DayNumber=((365*year+31*(month-1)+day+LeapFactor-StartMonth)-1)%7;
System.out.println("\n"+DisplayDay(DayNumber)+ " was Feb 29th in "+year);
for (int year1=year; year1>1582; year1++)
{
int DayNumber1=((365*year1+31*(month-1)+day+LeapFactor-StartMonth)-1)%7;
if(isLeapYear(year1) && DayNumber1==DayNumber)
{
System.out.println("\n"+year1+" is the next leap year where Feb. 29th happens on "+DisplayDay(DayNumber));
System.out.println("\n**********************************END************************************");
return;
}
}
}
public static String DisplayDay(int DayNumber){
switch (DayNumber)
{
case 0:
return "Sunday";
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
default:
return "";
}
}
}
解决方案 »
- 求思路
- tomcat部署.war包的不成功!(仅有20分)
- 请求请求一个struct2的action 在跳转后的页面的url中已接受到上页面传的参数 为什么在跳转后的页面中 取不到这些参数呢
- 急!急!急! 关于域认证的具体实现!!!!!
- 急!Tomcat5.0中如何指定到SERVLET
- 简单的javamail发邮件怎么不行呀?帮我看看,哪里有错误
- 请教xml文件中的${j2ee.home}取得是某个环境变量吗??
- 怎麼會有這樣的錯誤??.
- 什么时候用EJB,什么时候用jsp,javaBean,servlet才好呀?
- 求大佬看一下这个Tomcat启动不了是什么问题,谢谢!
- jsp 传值 post得不到值,get可以,为什么
- session在ie6下见鬼了!!!
• If the year is a leap year or not.
• If the given year is a leap year, your program should then display
1. which day of the week was Feb 29th, and
2. the next leap year where Feb. 29th happens on the same week day.
18961896 is leap yearSaturday was Feb 29th in 1896
61924 is the next leap year where Feb. 29th happens on Saturday**********************************END************************************
>Exit code: 0
>java -cp . LeapYear
Please enter a year greater than 1582.
19241924 is leap yearFriday was Feb 29th in 1924
51952 is the next leap year where Feb. 29th happens on Friday**********************************END************************************
>Exit code: 0