728x90
import java.io.*;
class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int year = Integer.parseInt(br.readLine());
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
System.out.print("1");
} else {
System.out.print("0");
}
}
}
import java.io.*;
class Main{
public static void main(String[] args) throws IOException {
// 두번째 방법
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int year = Integer.parseInt(br.readLine());
String result = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) ? "1" : "0";
System.out.println(result);
}
}
두번째방법이 코드 길이도 짧고 시간도 짧다.
조건이 길어서 가독성이 좋지 않아보인다.
728x90
'✍ Baekjoon' 카테고리의 다른 글
[백준/JAVA] (CLASS1) 10171번 고양이 (0) | 2022.06.07 |
---|---|
[백준/JAVA] (CLASS1) 9498번 시험 성적 (0) | 2022.06.07 |
[백준/JAVA] (CLASS1) 2741번 N 찍기 (0) | 2022.06.07 |
[백준/JAVA] (CLASS1) 2739번 구구단 (0) | 2022.06.07 |
[백준/JAVA] (CLASS1) 2557번 Hello World (0) | 2022.06.06 |