Is there any other way in Java to calculate a power of an integer?
I use Math.pow(a, b) now, but it returns a double, and that is usually a
Math.pow(a, b)
double
No, there is not something as short as a**b
a**b
Here is a simple loop, if you want to avoid doubles:
long result = 1; for (int i = 1; i <= b; i++) { result *= a; }
If you want to use pow and convert the result in to integer, cast the result as follows:
pow
int result = (int)Math.pow(a, b);