public int readInt(){
int x = 0;
String s;
try{
s = br.readLine();
}catch(IOException e){
s = "0";
} finally {
x = Integer.parseInt(s);
return x;
}
}
楼主要的是这种效果??~~~
int x = 0;
String s;
try{
s = br.readLine();
}catch(IOException e){
s = "0";
} finally {
x = Integer.parseInt(s);
return x;
}
}
楼主要的是这种效果??~~~
int x = 0;
try{
x = Integer.parseInt(br.readLine());
}
catch(IOException e){
//主要是异常时你想返回什么值,比如 x = -1;
}
return x;
}
int x = 0;
try{
x = Integer.parseInt(br.readLine());
return x;
}catch(IOException e){}
return -1; //可以根据需要定义“-1”为出现异常
}
此外还应该注意Integer.parseInt()还有可能抛出转型失败的异常,也需要扑捉