public class Solution { public static void main(String[] args) throws Exception { //напишите тут ваш код Scanner in = new Scanner(System.in); int a = in.nextInt(); boolean x = false; while (x) { if (a != -1) { a += a; continue; } else if (a == -1) { System.out.println(-1); break; } } } } 

How can I realize constant waiting for input in the console? before -1 is entered?

  • one
    apparently put int a = in.nextInt(); in the cycle - Alexey Shimansky
  • but then IDE swears that <a> is not declared - hellog888
  • Thank you, I put it in a loop. But before writing a comment about what the compiler curses. Deliberately deleted boolean x = false; :) Once again, my carelessness let me down. - hellog888

1 answer 1

It is more correct to check and not immediately take the value from the scanner.

 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int a = in.nextInt(); //.... } } }