Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.Scanner;
public class JavaExcercise {
 
 
  public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
 
        System.out.print("Input the year: ");
        int year = in.nextInt();
 
        boolean a = (year % 4) == 0;
        boolean b = (year % 100) != 0;
        boolean c = ((year % 100 == 0) && (year % 400 == 0));
 
        if (a && (b || c))
        {
            System.out.println(year + " is a leap year");
        }
        else
        {
            System.out.println(year + " is not a leap year");
        }
    }
}

Result:

Input the year: 2020

2020 is a leap year

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a Java program to input 5 numbers from keybo... >>
<< Write a Java program to test a number is positive ...