I have a problem with do while loop. I am displaying a dialogue box where a person should enter the type of quiz he had performed. The problem is that the user should enter only the following 3 words, either "Earthquake s" or "Place" or "Animals". If the user enters any other word, he/she should be displayed wwith another message saying "Invalid". This should keep repeatinf (i.e. displaying invalid) until the user enters either of those 3 words. When a user enters one of those words it will stop diplaying "Invalid". I tried doing this, but altough it displays "Invalid" when a user enters an invalid word, it will display invalid also when a user neters the correct word. I think i have something wrong with the loop.
This is the code:
This is the code:
Code:
String player = JOptionPane.showInputDialog(null, "Enter name");
String type = JOptionPane.showInputDialog(null, "Enter your quiz type");
do
{
type = JOptionPane.showInputDialog(null, "Invalid entry. Try again." );
}
while (type != "Earthquakes" || type != "Place" || type != "Animals" );
Comment