String parkingStringChoice;
System.out.println("Would you like to purchase parking? (Y or N)");
parkingStringChoice = scnr.nextLine();
int parkingChoice;
switch(parkingStringChoice) {
case "Y":
System.out.println("You have parking");
parkingChoice = 1;
break;
case "N":
System.out.println("You dont have parking");
parkingChoice = 0;
break;
}
if (parkingStringChoice != "Y" && parkingStringChoice != "N") {
System.out.println("Reenter valid input.");
System.exit(0);
}
The above portion is my code for a portion of my program asking if the user wants parking or not. I am trying to write an if statement to make sure if the user does not input Y or N it will print an error and then exit.
Instead of this, it is currently executing the if statement at all times, whether Y, N, or some other string is entered. Any help is appreciated, thanks.