搜索

怎么分辨闰年平年

发布网友 发布时间:2022-02-27 17:01

我来回答

3个回答

热心网友 时间:2022-02-27 18:30

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

热心网友 时间:2022-02-27 20:05

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:
case 7:
case 8:
case 10:
case 12:
System.out.println(year + "年" + month + "月的天数是31");
break;
case 4:
case 6:
case 9:
case 11:
System.out.println(year + "年" + month + "月的天数是30");
break;
case 2:
//嵌套if-else结构是否为闰年2月的判断
if (k)
System.out.println(year + "年" + month + "月的天数是29");
else
System.out.println(year + "年" + month + "月的天数是28");
break;
default:
System.out.println("输入月份错误!");
break;
}
}

我这个程序是
任意输入年月 判断在此年是否为闰年并判断输入的月份中有多少天 输出到控制台问题
判断是否为闰年 只要开头那一段就可以了

热心网友 时间:2022-02-27 21:56

4的整倍数年就是闰年,比如2004、2008能被4整除就是闰年。
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top