Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion The Arithmetic Operators

Related Tutorials


 
 

Share on Google+Share on Google+

The Arithmetic Operators

Advertisement
In this section we will learn how to calculate arithmetic operation. The java programming tutorial provide operators that perform the mathematical values addition, subtraction, multiplication, and division.

Java Example Using Arithmetic Operators

     

In this section we will learn how to calculate arithmetic operation. The java programming tutorial provide operators that perform the mathematical values addition, subtraction, multiplication, and division. 

Description of program:

In this section we will get the arithmetic values. First of all, we have to define class named "ArithmaticOperation" . Inside this class we have defined two static variable of  integer type. To assign the value of the numbers define a method main which is overloaded method. This method will take two parameter of integer type. These values will be used in following methods which have declared in this program. Now call the method one by one. To get the values of the two numbers call the overloaded method main() inside main() method. Output will be display on the screen by using println() method of the System class.

Here is the code of this program

import java.io.*;

class ArithmeticOperator {
  public static int num;
  public static int num1;
  public static void main(int num1, int num2){
  num=num1;
  num1=num2;
  }
  public int Addition(){
  return(num+num1);
  }
  public int Subtract(){
  return(num-num1);
  }
  public int Multiply(){
  return(num*num1);
  }
  public int Divide(){
  return(num/num1);
  }
  public static void main(String args[]){
  try{

  ArithmeticOperator arithmeticOperator= new ArithmeticOperator();
  BufferedReader object= new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the Number");
  arithmeticOperator.num=Integer.parseInt(object.readLine());
  arithmeticOperator.num1=Integer.parseInt(object.readLine());
  int addition=arithmeticOperator.Addition();
  int subtract=arithmeticOperator.Subtract();
  int multiply=arithmeticOperator.Multiply();
  int divide=arithmeticOperator.Divide();
  System.out.println("values is num="+ arithmeticOperator.num);
  System.out.println("value is num1="+ arithmeticOperator.num1);
  
  System.out.println("Addtion is="+ arithmeticOperator.Addition());
  System.out.println("Subtruct is="+ arithmeticOperator.Subtract());
  System.out.println("Multiply is="+ arithmeticOperator.Multiply());  
  System.out.println("Divide is="+ arithmeticOperator.Divide());
  }
  catch(Exception e){}
  
  }
  }



 Download this example

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 25, 2008

Related Tutorials

Discuss: The Arithmetic Operators   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
geeth
December 18, 2011
computers

please give it in a clear way. we are unable to understand.
DMCA.com