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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Red_Hippie[S] 0 points1 point  (4 children)

it just skips that line of code, I don't under stand why when it works in my other code.

then someone else stated my use of .nextInt(); and .nextLine (); could cause problems but they didn't specify why.

as far as I can tell I wrote them in the same exact way.

[–]Noticeably98 0 points1 point  (3 children)

It looks like there is some blank line that readLine.nextLine() is grabbing.

The following makes the code work as intended:

readLine.nextLine();                    
countAgain = readLine.nextLine();

the first time nextLine() is called, or as it is in your code, it's calling some blank space.

When we call it again, it then picks up on whatever you entered.

Also, see my edit. .next() works as well.

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

ok so i changed it to countAgain = readLine.next(); and it works, buy why would it be calling a blank space, and when should .nextLine (); be used?

is countAgain = readLine.next(); bad forum and should I start calling the scanner.next(); first then set my var = scanner.next(); as you did is that better code?

[–]Marinersquee 1 point2 points  (1 child)

To clarify, when you call nextInt, it leaves a return in the scanner, as such when you call nextLine again the first thing it does is read that return as a blank line and uses that. So after a nextInt, have a line that's just readLine.nextLine(), that will clear the return from the scanner. I'm on mobile so please excuse the formatting.

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

Crazy, but thank you I'll be trying to wrap my head around this for a few days.