(一)
截图:
程序:
import javax.swing.JOptionPane; public class Addition { public static void main (String args[]){ String firstNumber,secondNumber; int number1,number2,sum,cha,ji,chu; //read in first number from user as a string firstNumber= JOptionPane.showInputDialog("Enter first integer"); //read in second number from user as a string secondNumber= JOptionPane.showInputDialog("Enter second integer"); number1=Integer.parseInt(firstNumber); number2=Integer.parseInt(secondNumber); //convert numbers from type String to int sum=number1+number2; cha=number1-number2; ji=number1*number2; chu=number1/number2; JOptionPane.showMessageDialog(null, "the sum is"+sum,"Reesults", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(null, "the cha is"+cha,"Reesults", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(null, "the ji is"+ji,"Reesults", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(null, "the chu is"+chu,"Reesults", JOptionPane.PLAIN_MESSAGE); System.exit(0); } }