This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Question about in.next() for a database. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Question about in.next() for a database." Watch "Question about in.next() for a database." New topic
Author

Question about in.next() for a database.

David Spurgeon
Greenhorn

Joined: Oct 20, 2010
Posts: 14

After creating the scanner console and such, this is my code. I want the user to enter one of two options or it will generate an error message. However, I ALWAYS get the error message, no matter what I enter.



Output:

Enter the student's status (type either resident or nonresident)
resident
resident
Invalid status. Entry must be either resident or nonresident. Enter again

I'm sure this is some dumb error (of course), but I don't know what it is. What am I missing?

Thank you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
That is what comes from using == and != to test reference types for equality. Try the equals method.
David Spurgeon
Greenhorn

Joined: Oct 20, 2010
Posts: 14
Ah! I figured out what you mean. Took a little bit to determine how to use equals() to verify INequality, but it worked.
Thank you for the quick and helpful answer!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about in.next() for a database.
 
Similar Threads
compare two strings using compareTo
Insert for mysql
Forcing Input With The Scanner Class
can anyone help me with these exam question?
weird hasNextDouble behavior.