0
Please help me to know why contrasena and fcontrasena are not equal?
public void ingresarContrasena(String contrasena){ String fcontrasena; try{ String direccion="C:\\new folder\\registro\\"+correo+".txt"; File conar=new File(direccion); Scanner reader=new Scanner(conar); else{System.out.println("Correo no encontrado.");} while(reader.hasNext()){ fcontrasena=String.valueOf(reader.next()); if(contrasena==fcontrasena){ System.out.println("Contrasena correcta"); } else{ System.out.println("Contrasena incorrecta"); } } reader.close(); }catch(Exception e){} }
1 Odpowiedź
+ 1
Ok, i just solved using:
contrasena.equals(fcontrasena)
Aparrently both variables are allocated on different memory address and that is what "==" where comparing.
If you have a better explanation, let me know pls!