To write exponents in Java, use the
Math.pow
and Math.exp
function.Here's how you do it:
double twoToThePowerOfThree = Math.pow(2, 3);
double eToThePowerOfThree = Math.exp(3);
System.out.println(twoToThePowerOfThree); // 8.0
System.out.println(eToThePowerOfThree); // 20.085536923187668
Other useful functions include:
Math.log
- Natural logarithmMath.log10
- Base 10 logarithmMath.sqrt
- Square root