vendredi 19 juin 2015

If statement not working for Java [duplicate]

This question already has an answer here:

So when I run the code everything works until the if statement. I am very new to Java and I am confused why it isn't working

public static void main(String[] args){
    //Give name for instructor login
    String instructorLogin = ("Jonny");

    Scanner input = new Scanner(System.in);
    //Give prompt 
    System.out.println("Who shall pass?");
    //Get input
    String instructorAttempt = input.nextLine();
    //print input
    System.out.println(instructorAttempt);

    ***if(instructorAttempt == instructorLogin)***
    {
        System.out.println("Welcome!");
    }
    else{
        System.out.println("You shall not pass! You are not in out system!");
    }
}

Aucun commentaire:

Enregistrer un commentaire