62,614
社区成员
发帖
与我相关
我的任务
分享
if( (year%4 == 0 && year%400 !=0) || (year%400 == 0) ){
System.out.print("闰年");
}
else{
System.out.print("非闰年");
}
public static void main(String[] args) {
System.out.println("请输入一个年份:");
Scanner input = new Scanner(System.in);
int year = input.nextInt();
/*
* 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
*/
if (year % 4 == 0) {
if (year % 100 != 0&&year % 400 != 0) {
System.out.println(year + "这年是瑞年");
}else{
if (year % 400 == 0) {
System.out.println(year + "这年是瑞年");
} else {
//错误就在这里,不能被400整除的书并不一定不是闰年,比如404不能被400整除,但一样是闰年
System.out.println(year + "这年是平年");
}
}
}
}
public static void main(String[] args) {
System.out.println("请输入一个年份:");
Scanner input = new Scanner(System.in);
int year = input.nextInt();
/*
* 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
*/
if (year % 4 == 0) {
if (year % 100 != 0) {
System.out.println(year + "这年是瑞年");
}
}
if (year % 400 == 0) {
System.out.println(year + "这年是瑞年");
} else {
//错误就在这里,不能被400整除的书并不一定不是闰年,比如404不能被400整除,但一样是闰年
System.out.println(year + "这年是平年");
}
}
import java.util.*;
public class in {
public static void main(String[] args) {
System.out.println("请输入一个年份:");
Scanner input = new Scanner(System.in);
int year = input.nextInt();
/*
* 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
*/
if (year % 4 == 0) {
if (year % 100 != 0||year % 400 == 0) {
System.out.println(year + "这年是瑞年");
}else {
System.out.println(year + "这年是平年");
}
} else {
System.out.println(year + "这年是平年");
}
}
}
闰年怎么算的,搞忘了,不知道是不是这么算的。。
import java.util.*;
public class in {
public static void main(String[] args) {
System.out.println("请输入一个年份:");
Scanner input = new Scanner(System.in);
int year = input.nextInt();
/*
* 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
*/
if (year % 4 == 0) {
if (year % 100 != 0) {
System.out.println(year + "这年是瑞年");
}
}else if (year % 400 == 0) {
System.out.println(year + "这年是瑞年");
} else {
System.out.println(year + "这年是平年");
}
}
}