Enter two numbers, implement subtraction, and display the calculation results with a message box.
Yellow Star, 2015,9,29
Import Javax.swing.JOptionPane; Introduced. Joptionpane
public class Calculater
{
public static void Main (String args[])
{
Two numbers entered by the user.
String Firstnumber,secondnumber;
Two addend, and and, poor, product, quotient.
int number1,number2,add,sub,mul,div;
Enter a two number in the message box.
Firstnumber=joptionpane.showinputdialog ("Please enter the first number:");
Secondnumber=joptionpane.showinputdialog ("Please enter a second number:");
Converts the two number of inputs from a string to an integer.
Number1=integer.parseint (Firstnumber);
Number2=integer.parseint (Secondnumber);
A subtraction operation is performed on two integers.
Add=number1+number2;
Sub=number1-number2;
Mul=number1*number2;
Div=number1/number2;
Outputs the result of the calculation in a message box.
Joptionpane.showmessagedialog (NULL,
number1+ "+" +number2+ "=" +add+ "\ n"
+number1+ "-" +number2+ "=" +sub+ "\ n"
+number1+ "*" +number2+ "=" +mul+ "\ n"
+number1+ "/" +number2+ "=" +div+ "\ n");
Exit normally.
System.exit (0);
}
}
Two-digit subtraction using a graphical interface