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---

  1. if the year is divisible by 4 then go to step 2. Otherwise, go to step 5.
  2. if  year is divisible by 100 then go to step 3. Otherwise, go to step 4.
  3. if  year is divisible by 4 then go to step 2. Otherwise, go to step 5.
  4. this is a leap year. the method isLeapYear return true.
  5. 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;
}

}
}

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY