I'm trying to fill an arraylist with number but I don't want the user to have to press enter after each number. I would like it if they could put all the numbers on one line separated by white space like so.
Enter initial candy counts: 23 32 43 5 6 54
here what I have so far.
also if anyone can point me in the right direction about how to end the loop after they press enter would be much appreciated.
thank you.
Scanner userInput = new Scanner(System.in); ArrayList<Integer> candy = new ArrayList<Integer>(); int numCandy = 0; while() { System.out.println("Enter initial candy counts: "); numCandy = userInput.nextInt(); candy.add(numCandy); }