程序是想输入一些数字,然后最终算出结果
但是运行后退不出循环了。。。一直需要输入数据。
谁知道这是怎么回事啊?~:'(
import java.io.*;
public class AddDemo {
public static void main(String args[]) {
int m = 0, s = 0, i = 0;
String a = "", b = "";
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
while (a != null) {
System.out.println("输入一个整数,若输入完毕请输入回车");
System.out.print("现在请输入回车或数字:");
System.out.println();
try {
a = buf.readLine();
m = Integer.parseInt(a);
s += m;
} catch (Exception e) {
if (a == "")
a = null;
System.out.println("请输入整数!!!");
System.out.print("重新");
}
}
System.out.println("它们的和为" + s);
}
}
|