0
我不認爲這是可能的,因爲它會得到很多很多的情況下小麻煩,但我認爲這將至少是安全的問,有沒有一種方法,使:品格操作的公式
char operator = (Character) Utils.getProblemOperator(onPrev
? getPreviousMode()
: getMode());
Integer answer = -1, uanswer = Utils.getInt(answerField.getText());
if (operator == '+')
answer = (int) pInfo[onPrev ? 1 : 0][0] + (int) pInfo[onPrev ? 1 : 0][1];
else if (operator == '-')
answer = (int) pInfo[onPrev ? 1 : 0][0] - (int) pInfo[onPrev ? 1 : 0][1];
else if (operator == '×')
answer = (int) pInfo[onPrev ? 1 : 0][0] * (int) pInfo[onPrev ? 1 : 0][1];
else if (operator == '÷')
answer = (int) pInfo[onPrev ? 1 : 0][0]/(int) pInfo[onPrev ? 1 : 0][1];
關注這一部分:
answer = (int) pInfo[onPrev ? 1 : 0][0] + (int) pInfo[onPrev ? 1 : 0][1];
成類似:
answer = (int) pInfo[onPrev ? 1 : 0][0] operator (int) pInfo[onPrev ? 1 : 0][1];
最終的結果將是:
boolean onPrev = (boolean) pInfo[1][3];
char opperator = (Character) Utils.getProblemOperator(onPrev
? getPreviousMode()
: getMode());
Integer answer = -1, uanswer = Utils.getInt(answerField.getText());
answer = (int) pInfo[onPrev ? 1 : 0][0] operator (int) pInfo[onPrev ? 1 : 0][1];