因此,如果用户输入像 453-* 这样的后缀值,我的方法 EvalPostFix() 会起作用,但是当用户输入像 43*+ 这样的无效字符串或任何无效字符串时,程序希望程序重新提示用户输入不知道如何用 try catch 实现..
'
String in;
while(true){
System.out.println("Please enter the numbers first followed by the operators, make sure to have one less operator than of numbers");
try {
in = getString();
int result = EvalPostFix(in);
System.out.println(result);
} catch (IOException e) {
// TODO Auto-generated catch block
String s = "Not a valid postfix string";
e.toString();
in = getString();
}
}
'