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

Write a program that reads an integer value from the user, representing a year.

ID: 3862926 • Letter: W

Question

Write a program that reads an integer value from the user, representing a year. The purpose of this program is to determine if the year is a leap year in the Gregorian calendar. A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not by 400. For example, the year 2003 is not a leap year, but 2004 is. The year 1900 is a leap year because it is also divisible by 100, but the year 2000 is not a leap year because even though it is also divisible by 100, it is also divisible by 400. Produce an error message for any input less than 1582 (the year the Gregorian calendar was adopted).

Explanation / Answer

import java.util.Scanner;
public class Leap {

public static void main(String[] args) {
   int year;
   Scanner sc=new Scanner(System.in);
   System.out.println("Enter The Year U wanted To Check if Its Leap year or Not:");
   year=sc.nextInt();
   leapyear(year);
   sc.close();
}//End of Main Method

static void leapyear(int yr)   //To Evaluate the Entered Value By an User.
{
   if(yr<1582)
   {
       System.out.println("Gregorian Calendar was not Adopted Until 1582.");   //to check if its less than 1582
   }  
   else
   {
       if(yr%4==0 && yr%400!=0)    //To check if its divisible by 4 but not divisible by 400
       {
           System.out.println("Year "+yr+" is an Leap Year.");
       }
       else   //To print if not leap year
       {
           System.out.println("Year "+yr+" is Not an Leap Year.");
       }
   }
}//End of leapyear method
}//End of Class Leap

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote