Year 1 input from the console, or common year is a leap year is determined;

(Analysis method for determining leap: be divisible by 4 and can not be divisible by 400 and divided by 100)


public static void main(String[] args) {

      System.out.println ( "Please enter the year");

      Scanner scanner=new Scanner(System.in);

      int year=scanner.nextInt();

      if(((year%4)==0&&(year%100)!=0)||(year%400)==0) {

           System.out.println ( "the year you enter" + year + "is a leap year");

      }else {

           System.out.println ( "the year you enter" + year + "is not a leap year");

      }

           scanner.close();

}


Guess you like

Origin blog.csdn.net/weixin_40873693/article/details/78472352