Using a variable in a Java case statment
问题 I am making an expression parser for a calculator. The expressions will contain a variable, for instance, a user could enter "x + 2", or "y^2". I have a switch statement, and one of the cases in switch statement performs a certain action when it detects a variable: case variableSymbol: if (expression.length() == 1) { rangeResult = x1; break outer; } varFlag = true; varPos = expresPos; break; Originally, I hard coded a value 'x' in the above case, but I would like to give users a choice as to