搜题
问题   更新时间2023/10/10 13:30:00

import java.io.*;
public class Test {
public static void main(String args[]) throws IOException {
BufferedReader buf=new BufferedReader(
new InputStreamReader(System.in));
while(true) {
String str = buf.readLine();
if(str.equals("quit"))
break;
int x=Integer.parseInt(str);
System.out.println(x*x);
}
}
}
编译运行上面的程序:
从键盘输入10,回车后输出的结果如何?
从键盘输入exit,回车后程序能正确执行吗?为什么?

100 不能;因为方法Integer.parseInt(str)不能将字符串“exit”转化为整数,抛出异常。
王老师:19139051760(拨打)