Skip to content

Instantly share code, notes, and snippets.

@MrBean83
Last active August 29, 2015 14:21
Show Gist options
  • Save MrBean83/ab53eb4eb1609cd9d63e to your computer and use it in GitHub Desktop.
Save MrBean83/ab53eb4eb1609cd9d63e to your computer and use it in GitHub Desktop.
Simple "Leap Year" Program
import java.util.Scanner;
class LeapYear {
public static void main(String args[])
{
// Declare variables
int year;
boolean status;
Scanner scanIn = new Scanner(System.in);
System.out.println("Please enter a calendar year (or -1 to quit): ");
year = scanIn.nextInt();
while (year != -1) {
while (year < 1582) {
System.out.println("Sorry, that is not a Gregorian calendar year.");
System.out.println("Please enter a calendar year after 1582 A.D.: ");
year = scanIn.nextInt();
}
if (year % 400 == 0)
status = true;
else if (year % 100 == 0)
status = false;
else if (year % 4 == 0)
status = true;
else
status = false;
if (status)
System.out.println("That is indeed a leap year!");
else
System.out.println("Sorry, that is not a leap year...");
System.out.println();
System.out.println("Please enter a calendar year (or -1 to quit: )");
year = scanIn.nextInt();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment