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
Post a Comment