Two-digit subtraction using a graphical interface

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.