Event Handling in Java Console (IDE: IntelliJ IDEA)

Question:

Is it possible in the IntelliJ IDEA console to perform some action when a specific button is clicked?

For example. We have a menu:

  1. Roll_one
  2. Roll_ten
  3. Roll_ten

We want this or that method to be called when pressing 1, 2, or 3.

Answer:

java.util.Scanner scanner = new Scanner(System. in );
int number = scanner.nextInt();
switch (number) {
case 1:
    roll_one();
    break;
case 2:
    roll_two();
    break;
case 3:
    roll_three();
    break;
defult: 
    System.out.println("Type 1, 2 or 3");
    break;
}

And drive it all into a loop, if necessary.

Scroll to Top