[求救]如何使在用户输入非法字符时而不无限输出“输入的数不能数非数字”,
package imageio;import java.util.InputMismatchException;
import java.util.Scanner;
public class Try {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
int i,j;
Scanner shuru=new Scanner(System.in);
do{
try{
i=shuru.nextInt();
j=shuru.nextInt();
System.out.println(i/j);
}catch(InputMismatchException s){
System.out.println("输入的数不能是非数字");break;
}catch(ArithmeticException e){
System.out.println("除数不能是0");
}
}while(true);
}
}
[求救]如何使在用户输入非法字符时而不无限输出“输入的数不能数非数字”,而是让用户重新输入,小弟只能结束本次循环,请大虾帮忙指点一二!
页:
[1]
