I am having trouble with JOptionPane. My program is supposed to ask the user a question, if they answer Y is moves on to the next question. But if they answer N it asks another question. My problem is when the user answers with N it just moves on to the Y question. It is basically moving in the order the questions are asked and not following the parameters of the if-else statement. Here is my code:
import javax.swing.JOptionPane;
public class Helper2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
helpMe();
}
public static void helpMe(){
String ans = JOptionPane.showInputDialog("Does you car turn over? (Y/N)");
if (ans.equalsIgnoreCase("Y")){
JOptionPane.showInputDialog("Does it run rough? (Y/N)");
if (ans.equalsIgnoreCase("Y")){
JOptionPane.showInputDialog("Did you buy cheap gas (Y/N)");
} else if (ans.equalsIgnoreCase("N")){
JOptionPane.showInputDialog("Does it stop poorly? (Y/N)");
}
}else if (ans.equalsIgnoreCase("N")) {
JOptionPane.showMessageDialog(null, "Your battery is dead");
}else {
JOptionPane.showMessageDialog(null, "ERROR");
}
}
}
Aucun commentaire:
Enregistrer un commentaire