Type Here to Get Search Results !

Find Leap Year in Java using if else if conditionals.

0

              Leap  Year using Java program.


Find leap year or not leap year in java programming using if else if conditionals.

Question :-

A Leap year is the year that is multiple of 4. But, multiples of 100 which are not multiples of 400 are not leap years.

User Task :-

Input consists of the year value as an int. You need to print 1 in case of leap year and 0 otherwise.

Program :- 

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
       Scanner sc = new Scanner (System.in);
        int Y = sc.nextInt();
        if(Y%400==0){
            System.out.println(1);
        }
        else if(Y%100==0){
            System.out.println(0);
    }
    else if(Y%4==0){
            System.out.println(1);
}else {
            System.out.println(0);
}
    }
}



Sample Input:
2004

Sample Output:
1

Sample Input:
2000

Sample Output:
1

Sample Input:
1900

Sample Output:
0

Explanation :-

Since 1900 is divisible by 100 but not divisible by 400, so it is not a leap year.




Post a Comment

0 Comments