java - Missing return statement Error -


i started writing recursive methods. 1 of methods powers of ten giving me missing return type error.

public static double poweroften(int n) {   if (n == 0)   return 1;   if(n > 0)   return (10 * poweroften(n - 1));   if(n < 0)   return (1 / poweroften(n - 1));  } 

i'm pretty new explanation appreciated.

////// edit worked out me, negative , positive powers of ten. :d

public static double poweroften(int n) {   if(n > 0)   return (10 * poweroften(n - 1));   if(n < 0)   return (1 / poweroften( (-1)*(n) ));    return 1;  } 

try:

public static double poweroften(int n) {  if(n > 0)   return (10 * poweroften(n - 1));   if(n < 0)   return (1 / poweroften(n - 1));    return 1; } 

the compiler thinks can't guarantee there's value being returned since returns in if statements. doing way takes away confusion


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -