"Java 经典小程序:判断闰年(附答案)"

需积分: 15 3 下载量 128 浏览量 更新于2024-01-05 收藏 122KB DOC 举报
The given code is a Java program that checks whether a given year is a leap year or not. The program follows the following rules to determine if the year is a leap year: 1. If the year is divisible by 4 but not divisible by 100, it is a leap year. 2. If the year is divisible by 400, it is a leap year. The program starts by importing the Scanner class from the java.util package to allow user input. It then prompts the user to enter a year. The program checks if the entered year is within the valid range of 0 to 3000. If the year is invalid, the program displays an error message and exits. If the year is valid, the program checks if it satisfies the leap year conditions by using the modulo operator (%). If the year satisfies either of the conditions, it is considered a leap year, and the program prints a message stating that the year is a leap year. Otherwise, the program prints a message stating that the year is not a leap year. Finally, the program terminates.