HW3.18

时间:2021-04-03 19:44:01

HW3.18

 import javax.swing.JOptionPane;

 public class Solution
 {
     public static void main(String[] args)
     {
         String yearString = JOptionPane.showInputDialog(null, "Enter a year: \n", JOptionPane.QUESTION_MESSAGE);
         int year = Integer.parseInt(yearString);

         boolean isLeapYear = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));

         String output = "";
         if(isLeapYear)
             output = year + " is a leap year";
         else
             output = year + " is not a leap year";

         JOptionPane.showMessageDialog(null, output);
     }
 }

相关文章