Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Travis Chase
- // Project 2 If Statements
- // User has three attempts to enter their secret code to gain access to their "bank account".
- // Once all three attempts have been used, the user is blocked from entering their code.
- import java.util.Scanner;
- public class SecretCode {
- public static void main(String[] args) {
- int Secretcode = 51;
- int guess;
- Scanner stdin = new Scanner(System.in);
- System.out.println("Welcome to the People's Bank. Please enter your secret code.");
- guess = stdin.nextInt();
- if (guess != Secretcode) {
- System.out.println("Invalid code. Try again. (Attempt 2 of 3)");
- guess = stdin.nextInt();
- }
- if (guess != Secretcode) {
- System.out.println("Invalid code. Try again. (Attempt 3 of 3)");
- guess = stdin.nextInt();
- }
- if (guess != Secretcode) {
- System.out.println("Invalid code. Out of attempts.");
- System.exit(0);
- }
- else {
- System.out.println("Secret code accepted. Welcome back.");};
- }
- }
Add Comment
Please, Sign In to add comment