Advertisement
zerosensitivity

Con3

Sep 30th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class con3 {
  4.  
  5. static Scanner input = new Scanner(System.in);
  6. static int counter =0;
  7.  
  8.  
  9. public static void main(String[] args) {
  10. menu();
  11.  
  12. }
  13.  
  14.  
  15. public static void menu() {
  16.  
  17. System.out.println("Press 1 to say Hello");
  18. System.out.println("Press 2 to exit");
  19. int choice = input.nextInt();
  20.  
  21. if(counter==3) // use double equals for matching
  22. {
  23. System.out.println("Too many incorrect attempts shutting down");
  24. System.exit(0);
  25.  
  26. }
  27.  
  28.  
  29. switch (choice) {
  30. case 1:
  31. sayhello();
  32. break;
  33. case 2:
  34. System.out.println("closing program..");
  35. System.exit(0);
  36. break;
  37. default:
  38. counter++;
  39. System.out.println("Invalid choice. Please try Again");
  40. break;
  41. }
  42.  
  43. menu();
  44. }
  45.  
  46.  
  47. public static void sayhello() {
  48.  
  49. System.out.println("Say hello");
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement