我无法向控制台显示以使我的结果如下所示。这些数字只是示例,您应该能够使用任何数字的最终结果。
Operation Result
25+5 30
25-5 20
25*5 125
25/5 5
到目前为止,这是我的代码!
import javax.swing.JOptionPane;
public class Arithmetic {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//local variables
String firstNumber;
String secondNumber;
int number1;
int number2;
int sum;
// input = get First and Second Numbers from user
firstNumber = JOptionPane.showInputDialog("Enter first Number");
secondNumber = JOptionPane.showInputDialog("Enter Second Number");
// convert numbers from string to integer
number1 = Integer.parseInt(firstNumber);
number2 = Integer.parseInt(secondNumber);
// add the numbers
sum = number1 + number2;
sum = number1 - number2;
sum = number1 * number2;
sum = number1 / number2;
//display the results
System.out.println("Operation Result" );
System.out.println(number1 + "(+)" + number2 );
}
}