vendredi 27 avril 2018

Why is this Java code always giving me "False" statement? [duplicate]

This question already has an answer here:

When I type the same password (jalalkay) it gives me "False" answer!

import java.util.Scanner;

public class password2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner pass = new Scanner(System.in);


        System.out.println("Type a password");
        String ps = pass.nextLine();

        if(ps == "jalalkay"){
            System.out.println("true");

        }else{
            System.out.println("false");
        }

    }

}

Aucun commentaire:

Enregistrer un commentaire