Here's an example of a switch statement as part of a text-based adventure game. In this example, the switch statement is used to handle different player choices within the game. The program prints the part of the story and, based on his choice, outputs the continuation of the story. Decide which choice refers to which output and fill in the blanks in the switch statement.
Multiple conditions: switch
Adventure game
Report a typo
Fill in the gaps with the relevant elements
System.out.println("Welcome to the Adventure Game!");
System.out.println("Choose your path: 1) Forest, 2) Cave, 3) Castle");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println();
...
break;
case 2:
System.out.println();
...
break;
case 3:
System.out.println();
...
break;
default:
System.out.println();
break;
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.