-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmDemo.java
More file actions
38 lines (26 loc) · 767 Bytes
/
Copy pathAtmDemo.java
File metadata and controls
38 lines (26 loc) · 767 Bytes
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
package Week2;
import java.util.Scanner;
public class AtmDemo {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String userPin = "1234";
String guess;
int failCount = 0;
do {
System.out.println("Enter your PIN:");
guess = input.next();
if(!guess.equals(userPin)) { // it is wrong
System.out.println("Sorry, wrong!");
failCount = failCount + 1; // or failCount++
}
// if the user has failed 3 times
if(failCount == 3) {
System.out.println("So sorry. You are a failure.");
break;
}
} while(!guess.equals(userPin)); // ! is NOT
// guess == userPin would be comparing references, not values
System.out.println("Congratulations!");
input.close();
}
}