//input: multiple integers with spaces inbetween
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt())
{
//add number to list
}
sc.hasNextInt()
is waiting for an integer
. It only breaks out if you input a non-integer
character.
I saw a solution here before not too long ago but i cant find it anymore.
The solution (was the best if you ask me) was using two scanners. I cant seem to figure out how it used two scanners to go around this problem.
sc.NextLine()
maybe?
A user can input multiple integers the amount is unknown. Ex: 3 4 5 1. There is a space inbetween them. All i want to do is read the integers and put it in a list while using two scanners.