What is returned by the call: ben(51) ?
public static String ben(int x)
{
if(x / 5 <= 0)
return x % 5;
else return (x % 5) + ben(x / 5);
}
Here, the output will be an error because the function ben(int x) is suppossed to return 'String' datatype but it returns 'int' datatype.
The String in the declaration line : public static String ben(int x), says that the function is returning String value, but the return statements in the function is returning integer values.
To solve this error, we can replace the String in public static String ben(int x) with int which will return 3 as the return value for ben(51);
Get Answers For Free
Most questions answered within 1 hours.