문제
내가 제출한 정답
class Solution {
public int solution(int age) {
int answer = 0;
if(0<age&&age<=120){
answer = 2022-age+1;
}
return answer;
}
}
다른 사람이 제출한 정답(2022년 기준)
import java.time.*;
class Solution {
public int solution(int age) {
LocalDate today = LocalDate.now();
return today.getYear() - age + 1;
}
}
// 2024년 기준 return today.getYear()-2-age+1;
LocalDate 함수를 사용하여 연도를 받아오는 로직!!! 알아두기
Share article