본문 바로가기

프로그래머스/lv0

나이출력

/* 나이출력
 * 나이 age가 주어질 때, 2022년을 기준 출생 연도를 return
 *
 * age  result
 * 40   1983
 * 23   2000
 */
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class programmer_0_43 {
    static int a1 = 40;
    static int a2 = 23;
    public int solution(int age) {
        int answer = 0;
        return 2022 - (age - 1);
    }
    public static void main(String args[]){
        programmer_0_43 t = new programmer_0_43();
 
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        System.out.println("result2 = " + t.solution(a2));
        System.out.println("---------------------------------------");
    }
}
cs

'프로그래머스 > lv0' 카테고리의 다른 글

피자 나눠 먹기 (3)  (0) 2022.12.05
배열의 평균값  (0) 2022.12.05
각도기  (0) 2022.12.05
짝수의 합  (0) 2022.12.05
양꼬치  (0) 2022.12.05