I am trying to make a typing adventure kind of game in java, however i need a command at least similar to the one in the title, here is the code
import java.util
Your question makes an incorrect assumption. A switch()
statement is not a loop. It's shorthand for a bunch of if/else-if statements like this:
if(sc1.equals("Eat coconut")) {
System.out.println("You ate the coconut and got poisoned");
System.out.println("You died...");
}
else if(sc1.equals("Throw coconut")) {
//and so on
To do what you want, you will need an actual while() or for() loop. (The links will take you to Java tutorials explaining both constructions.)