Arithmetic operator in Java

Download
Download is available until [expire_date]
  • Version
  • Download 22
  • File Size 3.00 KB
  • File Count 1
  • Create Date April 26, 2016
  • Last Updated April 26, 2016

Arithmetic operator in Java

Arithmetic operator in Java

This is a sample code in java that demonstrate how the four basic arithmetic operators (add, subtract, divide, multiply) works. The program is also coded in console and gui version using swing library. The program will ask you to enter two numbers, and then it will compute and display the result of four arithmetic operators.

Source code:

import javax.swing.*;
class ArithmeticOperatorGUI {
public static void main(String[] args) {
String input1, input2;	
double num1, num2, sum, product, difference, quotient;

input1 = JOptionPane.showInputDialog(null,"enter first number: ");
num1=Double.parseDouble(input1);

input2 = JOptionPane.showInputDialog(null,"enter second number: ");
num2=Double.parseDouble(input2);

sum=num1 + num2;
product=num1 * num2;
difference=num1 - num2;
quotient=num1 / num2;

JOptionPane.showMessageDialog(null,"Sum: " + sum  + "
" + "Product: "+ product   
+ "
" + "Difference: " + difference + "
" + "Quotient: " + quotient  );

}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.