Unit 2 Lesson 5 and 8

I’m confused about when and why you have to put and extra input.nextLine() in with some scanners.

This comes up first in lesson 5 where you’re prompt appears before you can type in the response.

When I tried this in lesson 8 for choice a my variables isn’t being stored.

Can someone explain why this happens and how we know when we need to put in the extra . nextLine.

Sorry if this makes no sense.

1 Like

@jnail - Jennifer thanks for your post. Your question makes perfect sense. The nextLine() issue can be a bit confusing. This is particularly evident when you enter an integer and then try to enter a String. The system hangs onto the press on the “enter” key and assigns that value to the nextLine(). Since nextLine() already has a value, it ignores any other input. This YouTube video has a good explanation. Please let us know if you have any further questions.


Thank you that video helped a lot!!

Unit 2 lesson 6 slides bit confusion about tractor.Java but truck constructor. Around slide 140, 152 , and 147. Can someone check that for me. I m new at CSA.

Hi Rupali,
I just did this lesson today in my class, and I came across the same issue in the slides. The portion of the unit 2 guide for lesson 6 also has the same typos. The class on the right side of the slide-- the one that is not the Car class, should have matching file names, class header names and constructor. I found a mix of Tractor, Truck, and Car- is this what you are confused about? I corrected these typos on my copy of the slides, here are my versions of slides 140-142 which I believe to be correct. I emailed support@code.org to let them know about the issue.
Does this answer your question? please reach out if you have more questions :slight_smile:

1 Like

Thanks Lindsay for your response.
This reassurance helps.