Last active
December 27, 2015 09:49
-
-
Save joeyv/7306878 to your computer and use it in GitHub Desktop.
Determines if any year past 1581 is a leap year or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Leap{ | |
public static void main(String []args){ | |
int year,play; | |
System.out.println("[1] Enter year\n[2] Quit"); | |
Scanner scan = new Scanner(System.in); | |
play = scan.nextInt(); | |
while (play <= 2){ | |
if (play == 1) { | |
System.out.println ("Enter year:"); | |
year = scan.nextInt(); | |
if (year < 1582){ | |
System.out.println ("Enter a number greater than 1581"); | |
} else if (year >= 1582 && year % 4 >= 1) { | |
System.out.println ("Not a leap year"); | |
} | |
if (year >= 1582 && year % 4 == 0 && year % 100 >= 1) { | |
System.out.println ("Leap Year"); | |
} | |
if (year >= 1582 && year % 4 == 0 && year % 100 == 0 && year % 400 >= 1){ | |
System.out.println ("Not a leap year"); | |
} else if (year >= 1582 && year % 4 == 0 && year % 100 == 0 && year % 400 == 0){ | |
System.out.println ("Leap Year"); | |
} | |
} else if (play == 2) { | |
System.exit(1); | |
} | |
System.out.println("[1] Enter year\n[2] Quit"); | |
play = scan.nextInt(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Leap{ | |
public static void main(String []args){ | |
int year; | |
Scanner scan = new Scanner(System.in); | |
year = scan.nextInt(); | |
if (year < 1582){ | |
System.out.print ("Enter a number greater than 1581"); | |
} else if (year % 4 >= 1) { | |
System.out.println ("Not a leap year"); | |
} | |
if (year % 4 == 0 && year % 100 >= 1) { | |
System.out.println ("Leap Year"); | |
} | |
if (year % 4 == 0 && year % 100 == 0 && year % 400 >= 1){ | |
System.out.println ("Not a leap year"); | |
} else if (year % 4 == 0 && year % 100 == 0 && year % 400 == 0){ | |
System.out.println ("Leap Year"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment