7-2 闰年判断 (10 分)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_44547670/article/details/102757747

7-2 闰年判断 (10 分)

本题目要求读入1个整数年份,范围在0到3000内,然后判断是否是否闰年。如果是闰年输出为“Yes”,否则为“No”

输入格式:

2000

输出格式:

Yes

输入样例:

在这里给出一组输入。例如:

2000

输出样例:

在这里给出相应的输出。例如:

Yes

解答

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int year = in.nextInt();
		
		if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		in.close();
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_44547670/article/details/102757747