teacher让我专门创建一个方法来接收输入数据并判断类型,但是写完了每次都要输入三次才能继续,这是为什么?
public class Get {
Scanner sc=new Scanner(System.in);
public int get(int begin,int over){
while(!sc.hasNextInt()||sc.nextInt()<begin||sc.nextInt()>over){
System.out.println("输入格式错误!请重新输入。");
sc.next();
}
return sc.nextInt();
}
public double get(double begin,double over){
while(!sc.hasNextDouble()||sc.nextDouble()<begin||sc.nextDouble()>over){
System.out.println("输入格式错误!请重新输入。");
sc.next();
}
return sc.nextDouble();
}
}