Problem 3.18


 Question 3.18: Write a Java program that takes a year from user and print whether that year is a leap year or not.

Test Data

Input the year: 2016

Expected Output:

2016 is a leap year


Solution:


package com.company;
import java.util.Scanner;
public class lab3problem18 {
    public static void main(String[] args) {
        Scanner Obj = new Scanner(System.in);
        while (true) {
            System.out.print("Enter any year: ");
            int n = Obj.nextInt();

            if(n % 400 == 0)
            {
                System.out.println( n + "year is leap year");
            }
            else if (n % 4 == 0)
            {
                System.out.println( n + " year is leap year");
            }
            else if(n % 100 == 0)
            {
                System.out.println(n+"yaer is leap year ");
            }
            else{
                System.out.println(n + " year is not leap year");
            }
        }
    }
}
Previous Post Next Post