The problem is that each time in your loop, you call in.next()
three times:
while(running){
if(in.next().equalsIgnoreCase("exit")){
running = false;
}
if(in.next().equalsIgnoreCase("Hello_World")){
Hello_World.start();
}
if(in.next().equalsIgnoreCase("rps")){
Rock_Paper_Scissors.start();
}
}
When you get to the first if
, you call in.next()
, which gets the next token from the scanner. The problem is that when you get to the second if
, it will call in.next()
again, which will then try to get another token. It doesn't use the previous one, because you've told it to get a new one. To fix this, declare a variable to hold in.next()
at the beginning of the loop:
String input = in.next();
and then check the variable.