변수에 비트 단위 연산자를 할당하려고합니다. 내가 어떻게 해?자바의 변수에 비트 연산자를 할당하십시오.
예
String bitOp="";
String rFunction=JOptionPane.showInputDialog(null,"Enter Your round function","Round function",JOptionPane.INFORMATION_MESSAGE);
if(rFunction.toUpperCase()=="AND")
bitOp="&";
if(rFunction.toUpperCase()=="OR")
bitOp="|";
if(rFunction.toUpperCase()=="XOR")
bitOp="^";
int res= x +bitOp+ y; // if the operator is "AND" , this should be x & y.
//Here NumberFormatException error shows.
System.out.print(res);
그러나 그것은 작동하지 않습니다. 누구나 제발!
당신은 본질적으로
어쨌든 나는 두 번째 옵션을 선택한 것 "평가판"을하려고합니다. [this] (http://stackoverflow.com/questions/2605032/is-there-an-eval-function-in-java)를보십시오. – intboolstring
또한 계산을 수행해야합니다 ("bitOp"를 지정하지 않아야 함). –
열정과 같은 냄새가납니다. – chrylis