how to read space separated integers in java
# if you read from console
Scanner scanner = new Scanner(System.in);
List<Integer> list = new ArrayList<Integer>();
while (scanner.hasNextInt())
list.add(scanner.nextInt());
int[] arr = list.toArray(new int[0]);
# if you read from file
try {
File myObj = new File("filename.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextInt()) { // check for next integer in file
String data = myReader.nextInt(); // read the integer
System.out.println(data);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}