• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input help  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again.

I have completed this program and both the city and college name are printing out together. I can't see what I have done wrong. Thanks!

Java.PNG
[Thumbnail for Java.PNG]
 
MyExamCloud Software Support
Ranch Hand
Posts: 692
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use next() instead of nextLine()

 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use nextInt() to get the age, but that method only consumes the characters from the number. The carriage return/new line characters are still in the buffer. So when you call next() for the next question it sees the new line characters and returns you an empty String.

You need to add an extra next() method call after nextInt() but before the next question.
 
Sheriff
Posts: 4869
136
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a long but useful FAX on user input in Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!