• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input from console to array list behaves weirdly  RSS feed

 
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have this very simple application just to test console input:



When I let it run, only every third entry is put into the array list and I have to hit "enter" three times for the "break" in line 21 to trigger. I cannot find out why. Any hint would be appreciated.
 
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a start, why are you using == on Strings?
You are calling nextLine thrice per iteration of the loop, so you are going to add every third line to the List.
 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I was not aware it would work like that with scanner.nextLine(). Thanks.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!