例4.8 写一程序,判断某一年是否闰年。
时间: 2024-06-14 14:04:46 浏览: 89
c++-03-判断某一年是否为闰年.rar
以下是一个判断某一年是否为闰年的Java程序的例子:
```java
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter year: ");
int year = scanner.nextInt();
boolean leap = false;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
leap = true;
} else
leap = true;
}
if (leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}
```
阅读全文