0

This is my code:
It enters in the while loop ok but then won't go into any of the If statements.

public static void main(String [] args)
{   Scanner scan = new Scanner(System.in);
       System.out.print("Would you like to add a new component or find a 
       component? (A=add)(F=find): ");
       String action = scan.nextLine(); action=action.toUpperCase();

       while (select==true) {              
           if (action=="A") {
                System.out.print("Do you want to add a Resistor or Inductor? 
                (R=resistor)(I=Inductor): ");               
  • You should try look what is the value in action – parlad Sep 28 '18 at 04:45
  • Hi @Justin welcome to stackoverflow. In addition to what parlad mentioned you should also check out how to compare string values, assuming you're writing in Java you might be better off using the "equals" method rather than comparing with "==". Check https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java for further details – Stig Perez Sep 28 '18 at 05:09
  • Thanks for the help parlad and Stig. the == was the key. Changed to action.equals("A") and all is good. – Justin Hayden Sep 29 '18 at 22:24

0 Answers0