This tutorial will teach you Input two numbers to calculate and display the total.
paste the code inside the + button
1 2 3 4 5 6 | int Num1 = Integer.parseInt(txtNum1.getText()); int Num2 = Integer.parseInt(txtNum2.getText()); int tot = Num1 + Num2; txtTotal.setText(String.valueOf(tot)); |
paste the code inside the – button
1 2 3 4 5 6 | int Num1 = Integer.parseInt(txtNum1.getText()); int Num2 = Integer.parseInt(txtNum2.getText()); int tot = Num1 - Num2; txtTotal.setText(String.valueOf(tot)); |
paste the code inside the * button
1 2 3 4 5 6 | int Num1 = Integer.parseInt(txtNum1.getText()); int Num2 = Integer.parseInt(txtNum2.getText()); int tot = Num1 * Num2; txtTotal.setText(String.valueOf(tot)); |
paste the code inside the / button
1 2 3 4 5 6 | int Num1 = Integer.parseInt(txtNum1.getText()); int Num2 = Integer.parseInt(txtNum2.getText()); int tot = Num1 / Num2; txtTotal.setText(String.valueOf(tot)); |