The idea is you input a number and a recursive function will return a square of the entered number.
Example:
Enter a number: 5
Square of 5 is 25
The input and display is all figured out, but I can't solve the recursive function itself. It gives me StackOverflow error at line 15, which is return (N * squareOf(N));
Example:
Enter a number: 5
Square of 5 is 25
The input and display is all figured out, but I can't solve the recursive function itself. It gives me StackOverflow error at line 15, which is return (N * squareOf(N));
Code:
public static int squareOf(int N){
if(N == 0){
return 1;
}else if(N == 1){
return N;
}else{
return (N * squareOf(N));
}
}
Comment