1

I am trying to read Integer value after I hit space but using scanner it only works after I press Enter. How can I make it read the integers after the white space?

This is my code:

for (i = 0; i< n; i++) {
    scanner = new Scanner(System.in);
    list.add(scanner.nextInt());
}
Juan Carlos Mendoza
  • 5,203
  • 7
  • 21
  • 48
Marcos Guimaraes
  • 1,101
  • 3
  • 19
  • 46

1 Answers1

0

You cannot, it works that way System.in works that way, that buffer is flushed only upon pressing enter.

Antoniossss
  • 24,977
  • 3
  • 43
  • 86