A
A
Alexey Mikhailusov2014-12-07 18:44:22
Java
Alexey Mikhailusov, 2014-12-07 18:44:22

Doesn't work the second time nextInt. Why?

public static int in_try_int()
  {
    Scanner in = new Scanner(System.in);
      
    int Input=0;
    while(true)
    {
    try{		
      Input=in.nextInt();			
    }
    catch (java.util.InputMismatchException error)
    {
      System.out.println("Некорректный ввод. Повторите.");
      continue;
      
    }	
    break;
    }
    return Input;
    
  }

When an exception is caught and continue fires, nextInt does not fire a second time. And the program goes into an endless loop.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2014-12-07
@maaGames

How to move to the next int if the current one has already fallen? It iterates and tries to get the same int.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question