Java(消息框)
/ An addition program
import javax.swing.JOptionPane; // import class JOptionPane
public class yusuan {
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
sum1,sum2,sum3,sum4; // sum of number1 and number2
// 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 );
// add the numbers
sum1 = number1 + number2;
// subtract the numbers
sum2 = number1 - number2;
// multiply the numbers
sum3 = number1 * number2;
// divide the numbers
sum4 = number1 / number2;
// display the results
JOptionPane.showMessageDialog(
null, "The 和 is " + sum1, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate the program
}
}