[Programmers_CT] 11. 나이 계산

문정준's avatar
Feb 05, 2025
[Programmers_CT] 11. 나이 계산
💡
프로그래머스 코딩 테스트 11. 나이 계산

1. 문제 설명 - 빈칸 채우기

notion image

제한 사항

notion image

2. 입출력 예시

notion image
notion image

3. 코드 작성

import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year = sc.nextInt(); String age_type = sc.next(); int answer = 0; if (age_type.equals("Korea")) { answer = 2030 - year + 1; } else if (age_type.equals("Year")) { answer = 2030 - year; } System.out.println(answer); } }
  • 2030년의 한국 나이, 연 나이를 계산
    • 한국 나이는 2030 - 입력 받은 연도 + 1
    • 연 나이는 2030 - 입력 받은 연도
    • 한국 나이를 입력 받았을 경우 : “Korea”
      • answer = 2030 - year + 1;
    • 연 나이를 입력 받았을 경우 : “Year”
      • answer = 2030 - year;
 

4. 테스트 실행

notion image

5. 제출 후 채점

notion image
Share article

sxias