알고리즘/백준
[Python/Java] 백준 2753번 - 윤년
소꿍
2020. 6. 8. 16:47
https://www.acmicpc.net/problem/2753
2753번: 윤년
연도가 주어졌을 때, 윤년이면 1, 아니면 0을 출력하는 프로그램을 작성하시오. 윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때이다. 예를 들어, 2012년은 4의 배수이면서
www.acmicpc.net
Python
year = int(input())
if year % 4 == 0:
if (year % 100 != 0) or (year % 400 == 0):
print(1)
else:
print(0)
else:
print(0)
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
if(n % 4 == 0 && n % 100 != 0) {
System.out.println(1);
} else if (n % 4 == 0 && n % 400 == 0) {
System.out.println(1);
} else
System.out.println(0);
}
}