import java.util.Scanner;
import java.util.InputMismatchException;
Class Sum{
public static void main(String[] args) throws Exception{
Scanner s = new Scanner(System.in);
int sum = 0;
int input;
System.out.println("请输入一个整数");
while(true){
try {
input = s.nextInt();
if (input == 0) break;
} catch (InputMismatchException e) {
System.out.println("输入错误,请重新输入");
s.next();
}
}
System.out.println("所有数之和为" + sum);
}
}
全部代码都让别人写,这样就算了,当我没看着。