描述
请从标准输入流(控制台)中获取两个正整数 a,b,要求计算出 a 的 b 次方,并用 System.out.println 语句输出计算结果到标准输出流(控制台)。
1≤a,b≤5
样例
评测机会将整个项目的代码编译为一个可执行的 Main 程序,并按照这样的方式执行你的代码 Main,你的代码需要从标准输入流(控制台)中读入数据 a,b,每个参数单独一行,计算出结果后并打印到标准输出流(控制台)中。
样例一
当 a = 2,b = 3 时,程序执行打印出的结果为:
8
解释:
2 * 2 * 2 = 8
样例二
当 a = 5,b = 4 时,程序执行打印出的结果为:
625
解释:
5 * 5 * 5 * 5 = 625
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
// read data from console
// output the answer to the console according to the
// requirements of the question
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int answer = 1;
for(int i=1; i<=b; i++){
answer *= a;
}
System.out.println(answer);
}
}



