I am trying to have my program output an error code when the input values are too high, but I can only get it to display the error message in the terminal window, not in the method return. Here is the code:
public class AckermannAdvanced {
public static long ack (long m, long n) {
long ans;
System.out.print("\f");
if (m > 3 && n > 1) {
System.out.print("Input values are too high");
} else {
if (m == 2) ans = (2*n)+3;
else if (m == 1) ans = n+2;
else if (m == 0) ans = n+1;
else if (n == 0) ans = ack(m-1, 1);
else ans = ack(m-1, ack(m, n-1));
System.out.print(ans);
return(ans);
}
return 0;
}
}