vendredi 21 août 2015

"if" doesn't work with "keyboard.nextLine()"

I would have to write the correct password and if it is correct it say "password is correct"

When I write the correct password it say that it isn't correct.

Her is my code:

import java.util.Scanner;
class  myclass
{
public static void main(String args[]) 
{
Scanner keyboard = new Scanner(System.in);
String name;
String password;

System.out.println("give your name:\t");
name=keyboard.nextLine();
System.out.println("Hello"+name);
System.out.println("give your password:\t");
password=keyboard.nextLine();
keyboard.close();

if (password=="www")
{
    System.out.println();
    System.out.println("password is correct") ;
}
else 
{
    System.out.println();
    System.out.println("password isn't correct");        

}




}
}   

Aucun commentaire:

Enregistrer un commentaire