从键盘上录入两个整数,计算a的b次方的结果
/*** 从键盘上录入两个整数,计算a的b次方的结果*/import java.util.Scanner;public class Test25 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入底数:");int ds = sc.nextInt();System.out.println("请输入指数:");int zs = sc.nextInt();//计数变量long j = 1;for (int i = 1;i<=zs;i++){j*=ds;}System.out.println(ds+"的"+zs+"次方等于"+j);sc.close();}
}
执行代码如下: