Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created January 25, 2013 22:32
Show Gist options
  • Save Rembane/4638535 to your computer and use it in GitHub Desktop.
Save Rembane/4638535 to your computer and use it in GitHub Desktop.
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