Bouncy Number in Java

bookmark

import java.util.Scanner;
public class Year {
    public static void main(String[] args) 
    {
        // initializing the variable for entering the year value 
        int y;
        Scanner sc = new Scanner(System.in);
        // entering year, we want to check 
        System.out.println("Enter any Year:");
        y = sc.nextInt();
        sc.close();
        // initializing a boolean value .
        boolean leap = false;
        // checking year is devisable by 4 or not 
        if(y % 4 == 0)
        {
            // checking year is devisable by 100 or not 
            if( y % 100 == 0)
            {
                // checking year is devisable by 400 or not 
                if ( y % 400 == 0)
                    leap = true;
                else
                    leap = false;
            }
            else
                leap = true;
        }
        else {
            leap = false;
        }
         // printing the result .
        if(leap ==true)  
            System.out.println("\n"+ y  + " is a Leap Year.");
        else
            System.out.println("\n"+ y  + " is not a Leap Year.");
    }
}

 

Output:

Enter any Year:
1700
1700 is not a Leap Year.