输入a,b,求a的b次方

import java.util.Scanner;

public class Homework4 {
	public static void main(String[] args) {
		// 输入两个数求次幂方:如:3 3 27
		System.out.println("输入两个数:");
		Scanner scan = new Scanner(System.in);
		int power = 1;
		int a = scan.nextInt();
		int b = scan.nextInt();

		for (int i = 1; i <= b; i++) {
			power *= a;
		}
		System.out.println(a + "的" + b + "次方为" + power);
	}
}

 

你可能感兴趣的:(Java_实例)