I am trying to write a code that compares the users string to the string 'm' or 'f' and repeating the loop if the users answer doesn't match either letter
public static void main(String[] args) {
String om = JOptionPane.showInputDialog("I will calculate the number of chocolate bar you should eat to maintain your weigth\n"
+ "Please enter letter 'M' if you are a Male\n"
+ "'F' if you are a Female");
JOptionPane.showMessageDialog(null, om.equalsIgnoreCase("m"));
// if i don't do this, it says the variables have not been initialized
boolean m = true;
boolean f = true;
if (om == "m"){
m = om.equalsIgnoreCase("m");
} else if ( om == "f"){
f = om.equalsIgnoreCase("f");
}
JOptionPane.showMessageDialog(null, "The m is: " + m);
JOptionPane.showMessageDialog(null, "The f is: " + f);
//if the user enters one variable the other variable becomes false, thus
// activating the while loop
while (m == false || f == false){
om = JOptionPane.showInputDialog("Please enter letter 'M' if you are a Male\n"
+ "'F' if you are a female");
}
/* i tried using '!=' to compare the string that doesn't work, i tired converting the strings to number to make it easier something like the code below:
int g = 2;
if (om = "m"){
g = 0
}
while (g != 0){
}
that doesn't work either
So i tried using boolean which worked but if the user doesn't enter one letter the other letter becomes false and activates the while loop