알고리즘/그 외
SWEA - 1217. [S/W 문제해결 기본] 4일차 - 거듭 제곱
또또쪼
2020. 2. 23. 15:49
728x90
300x250
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
재귀함수를 이용해서 풀기
package algorithm;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class SWEA1217 {
public static int ans;
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
System.setIn(new FileInputStream("1217input.txt"));
Scanner sc = new Scanner(System.in);
for(int tc=0;tc<10;tc++) {
int T = sc.nextInt();
int n = sc.nextInt();
int m = sc.nextInt();
ans=1;
fun(n,m);
System.out.println("#"+T+" "+ans);
}
}
public static void fun(int n,int m) {
if(m==0)
return;
ans*=n;
fun(n,m-1);
}
}
728x90