Guest User

Untitled

a guest
Jun 19th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // Travis Chase
  2. // Project 2 If Statements
  3. // User has three attempts to enter their secret code to gain access to their "bank account".
  4. // Once all three attempts have been used, the user is blocked from entering their code.
  5. import java.util.Scanner;
  6. public class SecretCode {
  7. public static void main(String[] args) {
  8. int Secretcode = 51;
  9. int guess;
  10. Scanner stdin = new Scanner(System.in);
  11. System.out.println("Welcome to the People's Bank. Please enter your secret code.");
  12. guess = stdin.nextInt();
  13. if (guess != Secretcode) {
  14. System.out.println("Invalid code. Try again. (Attempt 2 of 3)");
  15. guess = stdin.nextInt();
  16. }
  17. if (guess != Secretcode) {
  18. System.out.println("Invalid code. Try again. (Attempt 3 of 3)");
  19. guess = stdin.nextInt();
  20. }
  21. if (guess != Secretcode) {
  22. System.out.println("Invalid code. Out of attempts.");
  23. System.exit(0);
  24. }
  25. else {
  26. System.out.println("Secret code accepted. Welcome back.");};
  27. }
  28. }
Add Comment
Please, Sign In to add comment