I received the error "possible loss of precision" on the last line of my code. Is it not possible to return a double?
My instructions were to create a program, called power, that took a double (x) and raised it to an integer (n) power.
package power;
/**
*
* @author Josh
*/
public class Main {
public static void main (String[] args) {
power (4.5, 5);
// invoke power
}
public static int power (double x, int n)
{
if (x == 0) {
return 0;
// if x = 0, then return 0 and terminate program
} else {
int recurse = power (x, n-1);
double result = x * recurse;
// recursive x^n
return result;
}
}
}