一个比较菜鸟的数据输入的验证问题..谢谢..# Java - 爪哇娇娃
o*i
1 楼
题目是这样的:
Write a code segment to prompt the user to input an integer between 0 and
100 (inclusive) and keep prompting the user until he does so. Verify both
the integer data type entered and the range.
我写的代码,有两个问题,一个是如果第一次输入的是小数,那会进入异常处理,可是
如果在catch的时候继续输入小数,那JAVA就处理不了了,然后就会出错。怎么才能改
进达到要求呢?谢谢!
import java.util.*;
public class Input {
public static void main(String[] args){
Scanner input= new Scanner(System.in);
boolean finish=true;
int i=-1;
while(finish){
Write a code segment to prompt the user to input an integer between 0 and
100 (inclusive) and keep prompting the user until he does so. Verify both
the integer data type entered and the range.
我写的代码,有两个问题,一个是如果第一次输入的是小数,那会进入异常处理,可是
如果在catch的时候继续输入小数,那JAVA就处理不了了,然后就会出错。怎么才能改
进达到要求呢?谢谢!
import java.util.*;
public class Input {
public static void main(String[] args){
Scanner input= new Scanner(System.in);
boolean finish=true;
int i=-1;
while(finish){