-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (31 loc) · 1.04 KB
/
Copy pathMain.java
File metadata and controls
40 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package PinLockSystem;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Secret PIN Lock System
Scanner scanner = new Scanner(System.in);
String correctPin = "1234";
String userPin;
int attempts = 0;
boolean accessGranted = false;
for (int i = 1 ; i <= 3 ; i += 1){
System.out.print("Enter 4-digit pin: ");
userPin = scanner.next();
attempts += 1;
if(userPin.length() == 4 && (userPin).equals(correctPin)){
System.out.println("Access Granded.");
System.out.println("Total attempts: " + attempts);
accessGranted = true;
break;
}
else{
System.out.println("Try Again!");
System.out.println("Remaing attempts: " + (3 - attempts));
}
}
if (!accessGranted) {
System.out.println("Account Locked!");
}
scanner.close();
}
}