Table of Contents
 Question:Â
Write a java program that performs an action to Find the leap year like output sample.
 Output Sample:  Â
1 2 3 4 5 6 7 8 |
Enter a Year: 2050 2050 Not Leap year Enter a Year: 2020 2020 Leap year Enter a Year: 1900 1900 Not Leap year |
 Source Code:Â
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Scanner; public class LeapYear { public static void main(String[] args) { //variable initialization int year; Scanner sc = new Scanner(System.in); //print input from the user System.out.print("Enter a Year: "); year = sc.nextInt(); //calculate leap year & print the output if(year % 400 == 0) System.out.println(year + " Leap Year"); else if(year % 100 == 0) System.out.println(year + " Not Leap Year"); else if(year % 4 == 0) System.out.println(year + " Leap year"); else System.out.println(year + " Not Leap year"); } } |