[Solved] The variable disappears at the end of the case [duplicate]


One of the problems is with this line:

   if (pass1 == newname & pass2 == newpassword){
      System.out.println("you are logged in");
     }else{
     System.out.println("incorrect passoword or login");
      }

If you will debug this code, You will notice that this if statement, doesn’t
compare the values of the String. For more details you may visit:
https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

Try this code instead:

        if(pass1.equals(newname) && pass2.equals(newpassword)) 
        {
            System.out.println("you are logged in");
        }else{
            System.out.println("incorrect passoword or login");
        }

second problem:

you need to put your switch statement in a while loop:

1.This why the program won’t end (and this way the variable) will be saved.

2.IF the user input is invalid instead of going to default, the program will also ask again for the user to write a number.

solved The variable disappears at the end of the case [duplicate]