Calculate the total number of Java programs in July February 29 during the two-day period.
I was just a newbie in the computer field and started learning Java not long ago. Later, I received a programming assignment about the total number of computing tasks in February 29 during the two-day period. In a rush, I wrote this program. Since we have no programming experience before, Java has only learned a small part. So the program has not solved the input problem.
My solution to this problem is:
The following is my code:
Public class LeapYearComputing
{
// Determine whether a year is a leap year.
Public static boolean leapYear (int y ){
Boolean leapYear;
If (y % 4 = 0 ){
If (y % 100 = 0 ){
If (y % 400 = 0 ){
LeapYear = true;
}
Else {
LeapYear = false;
};
}
Else {
LeapYear = true;
};
}
Else {
LeapYear = false;
};
Return leapYear;
};
// Determine whether a certain date exists, regardless of the year of BC.
Public static boolean dateExist (int year, int month, int date ){
Boolean dateExist;
If (year> 0 ){
If (month> 0 & month <13 ){
If (date> 0 & date <32 ){
Switch (month ){
Case 2:
If (leapYear (year )){
If (date <30 ){
DateExist = true;
}
Else {
DateExist = false;
};
}
Else if (date <29 ){
DateExist = true;
}
Else {
DateExist = false;
};
Break;
Case 4:
Case 6:
Case 9:
Case 11:
If (date <31 ){
DateExist = true;
}
Else {
DateExist = false;
};
Break;
Default:
If (date <32 ){
DateExist = true;
}
Else {
DateExist = false;
};
};
}
Else {
DateExist = false;
};
}
Else {
DateExist = false;
};
}
Else {
DateExist = false;
};
Return dateExist;
};
// Calculate the number of instances in January 1, February 29 during the two-day period.
Public static void main (String [] args ){
Int year1 = 555; // enter the start year.
Int month1 = 2; // enter the start month.
Int date1 = 28; // enter the start date.
Int year2 = 2012; // enter the end year.
Int month1 = 2; // enter the end month.
Int date2 = 28; // enter the end date.
Int result = 0;
Int Year = year1 + 1;
If (dateExist (year1, month1, date1 )){
If (dateExist (year2, mon2, date2 )){
While (Year <year2 ){
If (leapYear (Year )){
Result ++;
};
Year ++;
};
If (year1 = year2 & leapYear (year1 )){
Result --;
};
If (month1 <= 2 & leapYear (year1 )){
Result ++;
};
If (mon2> 2 | (mon2==2 & date2 = 29) & leapYear (year2 )){
Result ++;
}
System. out. println ("there are two dates" + result + "May February 29 ");
}
Else {
System. out. println ("the end date does not exist. ");
};
}
Else {
System. out. println ("the start date does not actually exist. ");
};
};
}
PS: this procedure does not consider the year of BC. I originally considered the situation of B. C., but I did not consider the situation of B. C., and the definition of a leap year is very likely not applicable, so I decided to limit the year to a later year.
When the start and end years are in the same year and the year is a leap year, the number of leap years should be reduced by one.
If you find any deficiencies in the program or have better algorithms, I hope you will give me more advice.