Leap year Challange
Write a method isLeapYear with a parameter of type int named the year
the parameter needs to be greater than or equal to1and less than or equal to 9999
if the parameter is not in the range return false.
Otherwise, if it is in the valid range, calculate if the year is a leap year and return true if it is a leap year, otherwise return false
to determine follow these steps---
- if the year is divisible by 4 then go to step 2. Otherwise, go to step 5.
- if year is divisible by 100 then go to step 3. Otherwise, go to step 4.
- if year is divisible by 4 then go to step 2. Otherwise, go to step 5.
- this is a leap year. the method isLeapYear return true.
- this is not a leap year. the method isLeapYear return false.
Soln
package com.cnc;
public class Leap_Year_Test {
public static boolean isLeapYear(int year) {
if (!(year >= 1 && year <= 9999)) {
return false;
} else {
int a = year % 4;
if (a == 0) {
int b = year % 100;
if (b == 0) {
int c = year % 400;
if (c == 0) {
return true;
} else
return false;
} else
return true;
} else
return false;
}
}
}