How to Do Exponents in Java

By Amber D. Walker

Java does not have an exponent operator like some other languages. Instead, you handle common mathematical operations in Java using the appropriately named Math static class in java.util.Math. Supported operations include those for finding the absolute value, common trigonometric functions, rounding and exponents. The results of these mathematical operations are nearly always "double" data-types, but you can cast them down to integers and floats.

Step 1

Open the Netbeans Integrated Development Environment, or IDE, or your preferred Java editor.

Step 2

Open an existing Java source file or create a new one by clicking "File" and "New Class."

Step 3

Add the following line to the top of the document:import java.util.Math;

Step 4

Type the following anywhere in the document to find an exponent:double result = Math.pow(number, exponent);Replace "number" with the base value and "exponent" with the exponent it is to be raised to. For example:double result = Math.pow(4,2);This results in 16, or 4^2.

References & Resources