It executes correctly the first time, but:
- It keeps printing "Please try again (Y/N)?" no matter what the input is after asking to continue.
I am unsure if != is appropriate to use for String comparison. I want to say while loopChoice "is not" Y or N, keep asking.
while(isLoop) { // Ask for user input System.out.print("Enter hours worked: "); hoursWorked = scn.nextInt(); System.out.print("Enter rate per hour: "); payRate = scn.nextInt(); scn.nextLine(); // Call functions to compute stuff ... // Print results ... System.out.print("\nDo you want to continue (Y/N)? "); loopChoice = scn.nextLine().toUpperCase(); while(loopChoice != "Y" || loopChoice != "N") { System.out.print("\nPlease try again (Y/N)? "); loopChoice = scn.nextLine().toUpperCase(); } switch(loopChoice) { case "Y": isLoop = true; System.out.print("\n"); break; case "N": isLoop = false; System.out.println("Terminating program..."); scn.close(); System.exit(0); break; default: System.out.println("Your input is invalid!"); isLoop = false; System.out.println("Terminating program..."); scn.close(); System.exit(0); break; } }