I'm writing a program that keeps track of team names and how many times that team has won a game based on user input. I need to allow for the user to input a String (for the team name) and an x to exit. I need to be able to compare a string and a character in a while loop (while (String != x)). So far I've tried:
char exitProgram = 'x';
String x = Character.toString(exitProgram);
while (winningTeam != x)
as well as:
while (winningTeam.charAt(0) != 'x')
However, neither of these result in a while loop that exits when x is entered. I'm not sure if it's a problem with trying to turn a char into a String or if I'm doing something else wrong but I'm pretty sure it's something I'm not understanding with the comparison. Any help is appreciated.
Edit: This has been marked as a duplicate of How do I compare strings in Java?
and while they're similar, I believe my question differs in needing to know how to compare a character to a string (i.e finding the correct character to string conversion) rather than just comparing two strings.