#Consume newline character

27 messages · Page 1 of 1 (latest)

errant yarrow
#

Hi, i'm trying to input some data thats in a for loop, but the second time i try to input data it skips the first one and goes to the second one. My question is how do i consume a newline character without having the user to press enter twice?

shut basaltBOT
#

This post has been reserved for your question.

Hey @errant yarrow! Please use /close or the Close Post button 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.

somber quiver
#

Example

quiet pagoda
frozen slate
#

It helps if you post the code you've written.

errant yarrow
# somber quiver Example

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

somber quiver
#

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

frozen slate
#

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.

frozen slate
#

Use nextLine like Kyo-chan said.

errant yarrow
#

but im trying get as input a character

frozen slate
#

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.

somber quiver
#

(Note that next() gets the next token, not caring whether it is one character long or more. So it fails to read a character)

errant yarrow
#

So how do i do what justis said?

somber quiver
#

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()

errant yarrow
#

yes but how do i grab the character out of the string as he said?

frozen slate
#

You're already doing that with the charAt calls.

somber quiver
#

How did you do it with next()?

frozen slate
#

Just replace every next() with nextLine() and you're good to go.

errant yarrow
#

OHhhh damn, thanks

shut basaltBOT
# errant yarrow 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.

errant yarrow
#

sorry for these type of question i just begun learning java a few monts ago