I wrote a program that users can login. Below u see some codes that I wrote for the password input but the second if
of them does not work properly.
Please help me to find the problem. Why it does not work?
import java.util.Scanner;
public class Password {
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");
}
}
}
See Question&Answers more detail:os