Here is my code that is going to take a user input year and output whether it is a leap year or not.
A year is a leap year if it is divisible by 4, unless it is divisible by 100 but not 400.
Also, they year entered has to be after 1582 otherwise it is invalid.
import java.util.Scanner;
public class StudentInformation
{
public static void main (String [] args)
{
System.out.println ("This program will determine whether a year is a leap year!");
Scanner x = new Scanner (System.in);
System.out.println ("\nPlease enter a year: ");
int year = x.nextInt ();
if (year > 1582 && year / 4 == 0)
{
if (year / 100 != 0 && year / 400 == 0)
{
System.out.println ("\n" + year + " is a leap year.");
}
else
{
System.out.println ("\n" + year + " is not a leap year.");
}
}
else if (year < 1582)
{
System.out.println ("\n" + year + " is not a valid number as the Gregorian calendar was not adopted yet.");
}
}
}