The Arithmetic Operators

Ads
 

The 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.

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

Ads

Ads