Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

year with 366 days is called a leap year. Leap years are necessary to keep the c

ID: 3912074 • Letter: Y

Question

year with 366 days is called a leap year. Leap years are necessary to keep the cal- endar synchronized with the sun because the earth revolves around the sun once every 365.25 days. Actually, that figure is not entirely precise, and for all dates after 1582 the Gregorian correction applies. Usually years that are divisible by 4 are leap years, for example 1996. However, years that are divisible by 100 (for example, 1900) are not leap years, but years that are divisible by 400 are leap years (for example, 2000). Write a program that asks the user for a year and computes whether that year is a leap year. Provide a class Year with a method isLeapYear. Use a single if statement and Boolean operators. java

Explanation / Answer

import java.util.*;
public class MyClass {

//isLeapYear method to check whether the year is leap year or not
public boolean isLeapYear(int year){
if((year%400==0)||((year%4==0) && (year%100!=0))){
return true;
}
else
return false;
}
//main method
public static void main(String args[]) {
MyClassm=new MyClass();
Scanner sc=new Scanner(System.in);
System.out.println("Enter the year:");
int year=sc.nextInt();
if(m.isLeapYear(year)) //function call to check for leap year
System.out.println(year +" is leap year ");
else
System.out.println(year +" is not a leap year ");
  
}
}