SWEA

swea 1217 [D3] [S/W 문제해결 기본] 4일차 - 거듭 제곱 JAVA

녁이 2023. 11. 24. 02:18
728x90
반응형

풀이 :

재귀함수 호출 -> m이 점차 감소하면서 0이되면 return

 


Code

public class Solution1217 {

    static int res, N, M;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        for (int tc = 1; tc <= 10; tc++) {
            int T = sc.nextInt();
            N = sc.nextInt();
            M = sc.nextInt();
            res = 1;
            pow(N, M);
            System.out.println("#" + T + " " + res);
        }
    }

    private static void pow(int n, int m) {
        if (m == 0) {
            return;
        }
        res *= n;
        pow(n, m - 1);
    }
}
728x90
반응형