public class PowerCalculator {
public static void main(String[] args) {
// 테스트 케이스
System.out.println("powerN(2,3) = " + powerN(2, 3)); // 8
System.out.println("powerN(3,3) = " + powerN(3, 3)); // 27
System.out.println("powerN(10,2) = " + powerN(10, 2)); // 100
}
// n제곱을 계산하는 메소드
public static int powerN(int base, int n) {
int result = 1;
// n번 곱하기
for(int i = 0; i < n; i++) {
result *= base;
}
return result;
}
}