【发布时间】:2016-01-31 05:33:29
【问题描述】:
do{
try{
System.out.println("Enter the no of People");
child = input.nextInt();
if(child < 0){
System.out.println("Enter a Positive Value");
}
}
catch(InputMismatchException e){
input.next();
System.out.println("(Invalid Input! Enter a numeric Value"); <---- Will give out the error if user enters a character
}
}while(child < 0);
当用户输入字母时,程序在错误后结束 我需要在它之后循环它
【问题讨论】:
-
对不起孩子 = input.nextInt();不是;对不起
-
进入do while前child的值是多少?如果为0或者是实例变量,则循环不会继续循环...
标签: java validation loops