0

In advance I am saying that this is for homework. The task is to check that if the input is "m" or "i" then the loop does not happen. However, if the letter is not "m" or "i" then the loop continues asking the user to input a correct answer. However, when I enter a different input to "m" or "i" then it bypasses the loop altogether even though I need it to. Could you please find out the problem?

Here is the code:

System.out.print("Would you like to enter your details using the metric (M) or imperial system (I)? ");
    szMetricOrImperial = szKeyboard.nextLine();
    szMetricOrImperial = szMetricOrImperial.toLowerCase();

 if (szMetricOrImperial == "m" && szMetricOrImperial == "i")
    {
        while (szMetricOrImperial == "m" || szMetricOrImperial == "i")
        {
            System.out.print("You entered in an incorrect value.\nPlease enter M or I: ");
            szMetricOrImperial = szKeyboard.nextLine();


            System.out.println();
        }
    }
red_star_12
  • 37
  • 1
  • 8

0 Answers0