lundi 5 octobre 2015

If else statement does not read user input [duplicate]

This question already has an answer here:

Whenever the user input is 1 or Jan, the code does not read and jump to second statement and display

Invalid month has been entered

        Scanner in = new Scanner(System.in);

        System.out.println("Enter a month:  ");

        String month=in.nextLine();


        if((month == "1") || (month == "Jan")){

            System.out.println("Month: January");
        }
        else{
            System.out.println("Invalid month has been entered");

Aucun commentaire:

Enregistrer un commentaire