当输入值太高时,我试图让我的程序输出错误代码,但我只能让它在终端窗口中显示错误消息,而不是在方法返回中。这是代码:
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;
}
}