/** * This program modifies Calculator1.java by getting * the numbers from the user. * * Class demo csc211 * Summer 2001 * Anthony Larrain */ import javax.swing.JOptionPane; class Calculator2{ public static void main( String [] args ) { int operand1, operand2, result; String textBoxInt1, textBoxInt2; textBoxInt1 = JOptionPane.showInputDialog("Enter integer"); textBoxInt2 = JOptionPane.showInputDialog("Enter integer"); operand1 = Integer.parseInt( textBoxInt1 ); operand2 = Integer.parseInt( textBoxInt2 ); result = operand1 + operand2; System.out.println("The sum is... " + result); // can skip the assignment to result. Note the parentheses are needed System.out.println("The difference is... " + (operand1 - operand2)); // Note the parantheses are not need but you can put them there for clarity // Why ? System.out.println("The product is... " + (operand1 * operand2)); result = operand1 / operand2; System.out.println("Their ratio is.. " + result); result = 17 % 3; System.out.print("When " + operand1 + " is divided by "); System.out.print(operand2 + " the remainder is " + result ); System.out.println(); } }