FRQ Methods and control structures
public class FRQ1 {
public static int numberOfLeapYears(int year1, int year2) { //create a static method
boolean isLeapYear = false; //create a boolean called isLeapYear
for(int i = year1 ; i <= year2 && i > 0; i++)
{
if (i % 4 ==0){ //determine if i(year) is or not a leap year
if (i % 100 == 0){
if (i % 400 == 0){
isLeapYear = true;
}
else {
isLeapYear = false;
}
}
else isLeapYear = true;
}
else isLeapYear = false;
if (isLeapYear){ //method that if the boolean is true(if i is a leap year), print the year
System.out.println(i + " is a leap year.");
}
}
return year1; //return code (no actual use, just to make sure the class goes well)
}
}
FRQ1.numberOfLeapYears(1900, 2000);