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);
}
} 作者: 伊文龙 时间: 2012-6-5 12:02
s += m;
} catch (Exception e) {
if (a == "") a = null;
System.out.println("请输入整数!!!");
System.out.print("重新");
}
}
问题出在判断语句上
public class Foo {
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 == "") {
System.out.println("输入一个整数,若输入完毕请输入回车");
System.out.print("现在请输入回车或数字:");
System.out.println();
try {
a = buf.readLine();
System.out.print(a);
m = Integer.parseInt(a);
System.out.print(m);
s += m;
System.out.print(s);
} catch (Exception e) {
if (a == "")
a = "";
System.out.println("请输入整数!!!");
System.out.print("重新");
}
}
System.out.println("它们的和为" + s);
}