程序设计思想:首先建立一个运算类,输入两个整数,设置一个变量分别赋值两数的加法运算结果,最后输出相应运算结果。
程序流程图:
源代码:import javax.swing.JOptionPane; // import class JOptionPane
public class yunsuan {
public static void main(String args[]) // TODO Auto-generated method stub
{
String firstNumber, // first string entered by user
secondNumber; // second string entered by user
int number1,number2,sum;
firstNumber=JOptionPane.showInputDialog("Enter first integer");
secondNumber=JOptionPane.showInputDialog("Enter second integer");
number1=Integer.parseInt(firstNumber);
number2=Integer.parseInt(secondNumber);
sum = number1 + number2;
JOptionPane.showMessageDialog( null, "The sum is " + sum, "Results",JOptionPane.PLAIN_MESSAGE );
System.exit(0);
}
}
实验截图: