I\'ve been trying to write a simple function in Java that can calculate a number to the nth power without using loops. I then found the Math.pow(a, b) class...
A recursive method would be the easiest for this :
int power(int base, int exp) { if (exp != 1) { return (base * power(base, exp - 1)); } else { return base; } }
where base is the number and exp is the exponenet
base
exp