dimanche 20 janvier 2019

if Scanner Boolean statement with 2 nextInt() and hasNextInt() issue

i write this code but when my password is correct i have issue.please guide me.i am new at java coding import java.util.Scanner;

public class PasswordProjectQ {

private static Scanner passwordInput;

public static void main(String[] args) {

    passwordInput = new Scanner(System.in);

    int builtInPassword = 3720118;

    System.out.println("Please enter your password:(just integer)");

    if(passwordInput.hasNextInt() && passwordInput.nextInt() != builtInPassword) {
        System.out.println("You entered the right format \nbut the password is WRONG!");
    }else if(passwordInput.hasNextInt() && passwordInput.nextInt() == builtInPassword) {
        System.out.println("Thanks,your password is correct");
    }else {
        System.out.println("WRONG format!");
    }

}

}

Aucun commentaire:

Enregistrer un commentaire