#Consume newline character
27 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @errant yarrow! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Example
If you are using a Scanner nextLine or skip will have the described behavior.
It helps if you post the code you've written.
Media is a class that has title, year, director , actors etc .Also find Person is a method that tries to find if that spesific actor has already been added
Prefer to use nothing but nextLine()
You've already been using Integer.parseInt(input.nextLine()) which is following that philosophy. So, be consistent and follow it always
You're using input.next() in your second screenshot in the while loop and right above it. That's causing you issues with not consuming the new line as you're wanting.
So how do i fix it?
Use nextLine like Kyo-chan said.
but im trying get as input a character
Just grab the character out of the string returned by nextLine.
If you're only grabbing one character, you're not going to be consuming the new line.
(Note that next() gets the next token, not caring whether it is one character long or more. So it fails to read a character)
So how do i do what justis said?
So, bear with me,
You do, like, type input, followed by a dot
And then nextLine, with the parentheses that show it's a method call
it looks line input.nextLine()
yes but how do i grab the character out of the string as he said?
You're already doing that with the charAt calls.
How did you do it with next()?
Just replace every next() with nextLine() and you're good to go.
OHhhh damn, thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
sorry for these type of question i just begun learning java a few monts ago