1 import javax.swing.JOptionPane; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 String yearString = JOptionPane.showInputDialog(null, "Enter a year: \n", JOptionPane.QUESTION_MESSAGE); 8 int year = Integer.parseInt(yearString); 9 10 boolean isLeapYear = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); 11 12 String output = ""; 13 if(isLeapYear) 14 output = year + " is a leap year"; 15 else 16 output = year + " is not a leap year"; 17 18 JOptionPane.showMessageDialog(null, output); 19 } 20 }
时间: 2024-10-12 05:37:55