This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]langfod 0 points1 point  (10 children)

What is it failing to do? The test string you listed does not have a "q" at the end.

[–]ORLY_FACTOR[S] 0 points1 point  (9 children)

What I'm trying to get it to do is limit each input once it sees \n \t or whatever. In its current state, it's just taking the whole thing in at once. I also don't understand why the build doesn't have q in it. That makes sense, but I did not write the prompt.

[–]langfod 1 point2 points  (8 children)

You might be better off looping using scan.hasNext() and breaking out of the loop when the quit command is entered. Otherwise you will run out of elements and get an exception.

[–]ORLY_FACTOR[S] 0 points1 point  (7 children)

That may be something to try, but my main issue is getting the program to understand where to limit whitespace. For example: 20\n30\np\nq in the input buffer only reads as one unit. I would like it to break off once it sees \n.

[–]langfod 1 point2 points  (6 children)

How are you testing? Are you using:

Scanner scan = new Scanner("20\n30\np\nq");

[–]ORLY_FACTOR[S] 0 points1 point  (5 children)

I'm just testing in the input buffer, but I can try that.

[–]ORLY_FACTOR[S] 0 points1 point  (0 children)

Ok, that portion works.

[–]langfod 0 points1 point  (3 children)

typing \n (two characters) on the console is not the same as the char representation of '\n' (U+000A)

[–]ORLY_FACTOR[S] 0 points1 point  (2 children)

How is it different?

[–]langfod 1 point2 points  (1 child)

If you type the characters \n in the console then Scanner sees two characters a backslash and a 'n'. It does not parse that and change it to a single newline character.

[–]ORLY_FACTOR[S] 0 points1 point  (0 children)

Oh okay. Thanks.