package leapYear;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class leapYear {
public static void main (String[] args){
String yearInput = JOptionPane.showInputDialog("Enter the year here: ");
Scanner inputScanner = new Scanner(yearInput);
int year = inputScanner.nextInt();
inputScanner.close();
boolean leapYear = false;
{
if (year % 400 == 0)
{
leapYear = true;
}
else if (year % 100 == 0)
{
leapYear = false;
}
else if (year % 4 == 0)
{
leapYear = true;
}
else
{
leapYear = false;
}
if (leapYear)
JOptionPane.showMessageDialog(null, year + " IS a leap year!");
else JOptionPane.showMessageDialog(null, year + " is NOT a leap year!");
}
}
}
Basically what I want to try to do, is to put in a year between say, 500-1000, and for the program to print every single leap year in that time period. I'm new to coding and have no idea how to go about this. Thanks.
Aucun commentaire:
Enregistrer un commentaire