mercredi 30 mai 2018

How to use else/if in password input?

i wrote a program that users can login. below u see some codes that i wrote for password input but the second if of them dos not work properly.please help me to find the problem. why it dos not work?

import java.util.Scanner;

public class Elevator {

    public static void main(String[] args) {

        Scanner passwordInput = new Scanner(System.in);
        System.out.print("Please enter your password: ");
        int builtInPassword=1254;

        if (passwordInput.hasNextInt() && passwordInput.nextInt()==builtInPassword) {
            System.out.println("Your password is correct.");
        } 


        else if(passwordInput.hasNextInt() && passwordInput.nextInt()!=builtInPassword){
            System.out.println("The password entered is incorrect");
        }



        else {
            System.out.println("Sorry, please enter the right format");
        }




    }

}

Aucun commentaire:

Enregistrer un commentaire