mardi 2 mars 2021

if else not working with scanner and joption? [duplicate]

hi i want to use JOption and Scanner for if and else, that if the word is correct than do the if statement , and ether do the else statement, but the problem is it always do the else statement. but it dose work if i put the word directly.

public static void main(String[] args) {
    
    String name = JOptionPane.showInputDialog(null, "test");

    if (name == "apple") {
        System.out.println("Correct");
    } else {
        System.out.println("Uncorrect");
    }

}

Aucun commentaire:

Enregistrer un commentaire