For my very first Java project I'm trying to make a simple text-based game. It seems like the or pipes do not work and when I try to enter something in after it doesn't work; I have to restart it.
public void GameStart() {
String playerName = "Player";
String Command = "Choice";
System.out.println("Type Start to start game!");
if(in.nextLine().equals("Start") || in.nextLine().equals("start")) {
Help();
print("Type Begin to start game :D");
if(in.nextLine().equals("Begin") || in.nextLine().equals("begin")) {
System.out.println("Who are you?");
Start and Begin works, but having the first letter lowercase like I used || for doesn't. When I use those I have to restart it because I can't type anything, but I clearly have or pipes that says to use either one. Does anyone have any idea what is causing this?
String str = in.nextLine();
str.equalsIgnoreCase("Start");
It will check both the lower and upper cases. You don't need to call equals() method twice, so it will optimize your code and readability.
I hope this will solve your issue.