Q:

Write a Java method to check whether an year (integer) entered by the user is a leap year or not

0

Write a Java method to check whether an year (integer) entered by the user 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("Enter a year: ");
        int year = in.nextInt();
 
        System.out.println(checkLeapYear(year));
    }
 
 public static boolean checkLeapYear(int year)
    {
        boolean a = (year % 4) == 0;
        boolean b = (year % 100) != 0;
        boolean c = ((year % 100 == 0) && (year % 400 == 0));
 
        return a && (b || c);
    }
}

Result:

Enter a year: 2020

true

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

total answers (1)

Write a Java method to calculate the area of a tri... >>
<< Write a Java method to compute the sum of the digi...