Write a Java Program to find given number is Leap or Not using else-if
import java.util.Scanner; public class Leap { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("\n Enter Year: "); int Year = s.nextInt(); if ( Year % 400 == 0) { System.out.println("\n"+Year+" is a Leap Year. "); } else if (Year%100 == 0) { System.out.println("\n"+Year+" is NOT a Leap Year. "); } else if(Year%4 == 0) { System.out.println("\n"+Year+" is a Leap Year. "); } else { System.out.println("\n"+Year+" is a NOT Leap Year. "); } } }
Output:
Enter Year: 2014
2014 is a NOT Leap Year.
No comments:
Post a Comment
If you have any doubts, please let me know