Java有指数运算符吗?
Java中是否有指数运算符?
例如,如果系统提示用户输入两个数字,并且他们输入 和 ,则正确答案为 。3
2
9
import java.util.Scanner;
public class Exponentiation {
public static double powerOf (double p) {
double pCubed;
pCubed = p*p;
return (pCubed);
}
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
double num = 2.0;
double cube;
System.out.print ("Please put two numbers: ");
num = in.nextInt();
cube = powerOf(num);
System.out.println (cube);
}
}