java - How to scan through an InputFile? -


currently have while loop reads through input file named "input". input file contains numbers, such "1 2 3 4" represent irrelevant question. receive number "1", use scanner.nextint(); if correct way receive 1, stuck on how receive other numbers 2 3 4.

while(scanner.hasnext()){      int firstnum = scanner.nextint();     // how second, third, , fourth number?      //it not guaranteed given 4 numbers, given @ least many. 

just continue loop , accumulate numbers encounter, e.g., list:

list<integer> numbers = new linkedlist<>(); while(scanner.hasnext()) {     numbers.add(scanner.nextint()); } 

Comments