计算X^n的方法

版权声明:使用注明出处 https://blog.csdn.net/chunfenxiaotaohua/article/details/82896321
package test1;
import java.util.Scanner;
public class Square {

	public static void main(String[] args) {
		double result=0;
		double t=0;
		Scanner sca=new Scanner(System.in);
		System.out.println("请输入指数");
		int power =sca.nextInt();//从键盘输入
		System.out.println("请输入底数");
		double truth= sca.nextDouble();//从键盘输入
		t=truth;
		for(int i=0;i<power-1;i++)
		{

			truth= truth*t;
		}
		result=truth;
		System.out.println("result is :"+result);
	}
}

猜你喜欢

转载自blog.csdn.net/chunfenxiaotaohua/article/details/82896321
今日推荐