我必須計算來自單獨JTextfields的兩個輸入,在組合框中選擇一個運算符,並根據所選運算符計算結果。但是,我得到0作爲我的答案。我怎樣才能計算結果沒有得到0?從Java計算器中獲取結果
private void jButton1_actionPerformed(ActionEvent e) {
int x = Integer.parseInt(jTextField1.getText());
int y = Integer.parseInt(jTextField2.getText());
String Result = "0";
jLabel4.setText(Result);
int total = Integer.parseInt(Result);
if(Operator.equals("+")) {
total = x + y;
}
else if(Operator.equals("-")) {
total = x - y;
}
else if(Operator.equals("*")) {
total = x * y;
}
else if(Operator.equals("/")) {
total = x/y;
}
}