import javax.swing.JOptionPane; // import class JOptionPane public class sumit{ public static void main( String args[] ) { String firstNumber, // first string entered by user secondNumber; // second string entered by user int number1, // first number to add number2; // second number to add // 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" ); // convert numbers from type String to type int number1 = Integer.parseInt( firstNumber ); number2 = Integer.parseInt( secondNumber ); // display the results JOptionPane.showMessageDialog( null, "The sum is: / 和数是: " +(number1+number2) +"\n"+"The difference is: / 减数是:"+(number1-number2) +"\n"+"The product is: / 积是:"+(number1*number2) +"\n"+"The division is: / 商是:"+(number1/number2) ); System.exit( 0 ); // terminate the program } }
原文:http://www.cnblogs.com/kk-95/p/4859856.html