怎么分辨闰年平年

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:57:48

不全是
if((year%4)||((year%100)&&!(year%400))printf("ping nian);
else printf("run nian");
就是对于不是整百的年能被4整除就润,否则平,对于是整百的要看是否能被400整除

4的整倍数年就是闰年,比如2004、2008能被4整除就是闰年。

import java.util.Scanner;

public class RnYear {

public static void main(String[] args) {
System.out.print("请输入任意年份:");
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
// 判断是否闰年 设置布尔型变量存储判断结果
boolean k = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
System.out.println(year + "年是闰年!");
} else {
System.out.println(year + "年不是闰年!");
}

System.out.print("请输入任意月份:");
int month = sc.nextInt();
//用switch结构判断月份天数
switch (month) {
case 1:
case 3:
case 5: