0% found this document useful (0 votes)
2 views

10.1 Registration app source code

The document contains a Java program that prompts the user to enter a name and password for authentication. It allows three attempts to enter the correct credentials, providing feedback on incorrect entries. If the user fails to enter the correct name or password within three attempts, the program terminates with a message indicating all chances have been used.

Uploaded by

alarcon17722
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

10.1 Registration app source code

The document contains a Java program that prompts the user to enter a name and password for authentication. It allows three attempts to enter the correct credentials, providing feedback on incorrect entries. If the user fails to enter the correct name or password within three attempts, the program terminates with a message indicating all chances have been used.

Uploaded by

alarcon17722
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Scanner sc = new Scanner(System.

in);
String name = "SS Academy";
String password = "12345";
int pass = 3;

while (true) {

System.out.println("Please enter your name");


String nameInput = sc.nextLine();
System.out.println("Please enter your password");
String passwordInput = sc.nextLine();

if (name.equals(nameInput) && password.equals(passwordInput)) {


System.out.println("You entered your name and password correctly");
System.out.println("Welcome");
break;

} else if (! (name.equals(nameInput)) &&


password.equals(passwordInput)) {
System.out.println("You entered your name false");
pass -= 1;
System.out.println("Your chance == " + pass);

} else if (name.equals(nameInput) && !(password.equals(passwordInput)))


{
System.out.println("Password is incorrect");
pass -= 1;
System.out.println("Your chance == " + pass);

} else if (!(name.equals(nameInput)) && !


(password.equals(passwordInput))) {
System.out.println(" Password and name are both wrong");
pass -= 1;
System.out.println("Your chance == " + pass);

}
if (pass == 0) {
System.out.println("You used all your chances");
break;
}
}

You might also like