[알고리즘]JAVA 거듭제곱(Power)

정답

 

코드

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int num1;	//제곱할 숫자
		int num2;	//반복할 숫자
		
		System.out.println("숫자 1: ");	//제곱
		num1 = sc.nextInt();
		System.out.println("숫자 2: ");	//반복
		num2 = sc.nextInt();
		
		int result = num1;	
		
		for (int i=0;i<num2-1;i++) {
			
			result *= num1;
			
		}
		System.out.println(result);
	}

 

댓글

Designed by JB FACTORY