문제
https://www.acmicpc.net/problem/2753
2753번: 윤년
연도가 주어졌을 때, 윤년이면 1, 아니면 0을 출력하는 프로그램을 작성하시오. 윤년은 연도가 4의 배수이면서, 100의 배수가 아닐 때 또는 400의 배수일 때이다. 예를 들어, 2012년은 4의 배수이면서
www.acmicpc.net
풀이
- 수학, 구현
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
if((year%4 == 0 && year%100 != 0) || (year%400 == 0)) {
System.out.println(1);
} else {
System.out.println(0);
}
}
}
'코딩테스트 > BOJ' 카테고리의 다른 글
[백준/파이썬] 1373번: 2진수 8진수 (Python) (0) | 2021.06.20 |
---|---|
[백준/파이썬] 10951번: A+B - 4 (Python) (0) | 2021.06.19 |
[백준/파이썬] 1373번: 2진수 8진수 (Python) (0) | 2021.06.15 |
[백준/파이썬] 1769번: 3의 배수 (Python) (0) | 2021.04.28 |