xxxxxxxxxx
console.log(Math.pow(2, 4)); // 16
console.log(Math.pow(3, 3)); // 27
// Negative bases to fractional exponents return NaN:
console.log(Math.pow(-7, 1/3)); // NaN
xxxxxxxxxx
// Math.pow()
// The Math. pow() method returns the value of x to the power of y (xy).
// EXAMPLE : 1
let powerOf = Math.pow(2,5);
console.log(powerOf);
// OUTPUT: 32
// EXAMPLE : 2
let powerOf2 = Math.pow(-2,5);
console.log(powerOf2);
// OUTPUT: -32
// EXAMPLE : 3
let powerOf3 = Math.pow();
console.log(powerOf3);
// OUTPUT: NaN
xxxxxxxxxx
import java.lang.*;
public class MathDemo {
public static void main(String[] args) {
//what is Math.pow(3, 2)?
double x = 3;
double y = 2;
System.out.println("Math.pow(" + x + "," + y + ")=" + Math.pow(x, y));
}
}
//the Output is 9
xxxxxxxxxx
Math.pow(base, exponent);
Math.pow(10, -2);
// Outputs 16
// The same as going 2^4, 2 to the power of 4