提示:需要知道闰年和平年的概念。需要知道java的基本语法规则。
package studying; import java.util.Scanner; public class JudgmentYear { /* * Determine whether the year entered is common or leap years? */ public static void main(String[] args) { Scanner input = new Scanner(System.in); for(int i = 0; ; i++) { System.out.println("Please enter year:"); int year = input.nextInt(); if(year % 4 != 0 || year % 100 == 0 && year % 400 != 0) { System.out.println(year + " is common year"); }else { System.out.println(year + " is leap year"); } } } }
结果展示: