有人知道为什么这段代码陷入无限循环吗?在没有输入整数的情况下运行后,它将无限重复“请输入整数”
class ExceptionHandling {
public static void main(String[] args) {
int foo= getInteger();
}
public static int getInteger() {
Scanner in = new Scanner(System.in);
while(true)
{
int delta = 0;
try
{
delta = in.nextInt();
return delta;
}
catch (Exception ex)
{
System.out.println("Please enter an integer");
}
}
}
}