Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class con3 {
- static Scanner input = new Scanner(System.in);
- static int counter =0;
- public static void main(String[] args) {
- menu();
- }
- public static void menu() {
- System.out.println("Press 1 to say Hello");
- System.out.println("Press 2 to exit");
- int choice = input.nextInt();
- if(counter==3) // use double equals for matching
- {
- System.out.println("Too many incorrect attempts shutting down");
- System.exit(0);
- }
- switch (choice) {
- case 1:
- sayhello();
- break;
- case 2:
- System.out.println("closing program..");
- System.exit(0);
- break;
- default:
- counter++;
- System.out.println("Invalid choice. Please try Again");
- break;
- }
- menu();
- }
- public static void sayhello() {
- System.out.println("Say hello");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement