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
Well you can simply use Math.pow(a,b)
as you have used earlier and just convert its value by using (int)
before it. Below could be used as an example to it.
int x = (int) Math.pow(a,b);
where a
and b
could be double
or int
values as you want.
This will simply convert its output to an integer value as you required.