You should test Strings for equality using equals()
, not ==
.
if ("quit".equals(hex)) {
Expression hex.equals("quit")
is correct too, it's good convention to prefer constant.equals(variable)
form for better null safety.
Also note, you specified
I want it to break when the user types "break" into the console
but you are comparing the variable hex
against a different string. The code above will break (i.e. get out of the loop) if the user types "quit" and not "break".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…