.输入一个年份 看是否是闰年,输出闰年的条件是: (1).能被4整除,但同时不能被100整除的年份

2025-02-22 14:35:51
推荐回答(4个)
回答1:

System.out.println("请输入年份:");
Scanner year = new Scanner(System.in);
int y = Integer.parseInt(year.next());
if (y % 400 ==0) {
    System.out.println(y + "年是闰年。");
}else if(y%4 == 0 && y%100 != 0) {
    System.out.println(y + "年是闰年。");
}else {
    System.out.println(y + "年不是闰年。");
}

回答2:

import java.util.Scanner;


public class Runnian {


public static void main(String[] args) {
int year = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入年份(如1999)");
year = scanner.nextInt();

if(year%400==0 || (year%4==0 && year%100>0)){
System.out.println(year+"是闰年");
}

}

}

回答3:

System.Console.WriteLine("请输入年份");
string str = System.Console.ReadLine();
int a = System.Convert.ToInt32(str);
if (a%4==0 && a%100!=0)
{
System.Console.WriteLine("闰年");

}
else if (a %400==0)
{
System.Console.WriteLine("闰年");
}
else
{
System.Console.WriteLine("不是闰年");
}

回答4:

您好,请问具体题目是什么,需要一个判断瑞年的函数吗?