I don't know why the lines won't print in the while loop. I can't exit either. Please help. The program runs but nothing inside the while loop will print.
public class RomanNumeralHelper {
/**
* (Insert a brief description that describes the purpose of this method)
*
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String myRoman;
String upperRoman;
System.out.print("Enter a roman numeral [Q | q to quit]: ");
myRoman = in.next();
upperRoman = myRoman.toUpperCase();
while (upperRoman != "Q") {
if (upperRoman == "I") {
System.out.println(">> 1");
} else if (upperRoman == "II") {
System.out.println(">> 2");
} else if (upperRoman == "III") {
System.out.println(">> 3");
} else if (upperRoman == "IV") {
System.out.println(">> 4");
} else if (upperRoman == "V") {
System.out.println(">> 5");
}
System.out.print("Enter a roman numeral [Q | q to quit]: ");
myRoman = in.next();
upperRoman = myRoman.toUpperCase();
}
System.out.println("Good Bye!");
// (5) Closes the in object to avoid a resource leak.
in.close();
}
}