I am having trouble with delimiters. My code is as follows:
Scanner in=new Scanner(System.in);
in.useDelimiter("\\D");
int x,y,z;
System.out.println("Enter 3 digits: ");
x=in.nextInt();
y=in.nextInt();
z=in.nextInt();
System.out.println(x + " " + y + " " + z);
in.close();
Pardon my lack of experience with delimiters, but I can only get my program to separate input with 1 character, not two. The program must be able to take input as follows:
either 1 2 3
or 1, 2, 3
.
currently it can handle 1 2 3
and 1,2,3
but not 1, 2, 3
The extra spaces in the last case must be throwing it off. How do you handle this?
Additionally, I must be able to take in a variable number of integers as input, up to 100 integers, and insert them into a queue. Obviously the three variables I have defined are not enough but clearly defining 100 would also be overkill. What is the most efficient way to handle this? Thanks in advance.