Created
January 25, 2013 22:32
-
-
Save Rembane/4638535 to your computer and use it in GitHub Desktop.
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 javax.swing.*; | |
public class Shootyear { | |
public static void main(String[] args) { | |
int år = 0; | |
String indata = ""; | |
while (indata != null) { | |
do { | |
try { | |
indata = JOptionPane.showInputDialog("Ett år tak"); | |
if (indata != null) { | |
år = Integer.parseInt(indata); | |
if (isShootyear(år)) { | |
JOptionPane.showMessageDialog(null, "är ett skottår"); | |
} else { | |
JOptionPane.showMessageDialog(null, "är inte ett skottår"); | |
} | |
} | |
} catch (NumberFormatException nfeException) { | |
JOptionPane.showMessageDialog(null, "det där var fan inte ett år"); | |
} | |
} while (indata == null); | |
} | |
} | |
public static boolean isShootyear(int year) { | |
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment