1. Arithmetic operators are used to perform fundamental arithmetic operations like addition,subtraction,etc.
  2. There are 5 arithmetic operators in java and these operators act an two operands at a time,hence these are called as “Binary Operators.

Example: a=13,b=5

Operator Meaning Example Result
+ Addition Operator a+b 18
Subtraction Operator a-b 8
* Multiplication Operator a*b 65
/ Division Operator a/b 2.6
% Modules Operator a%b 3

When ever we are applying any arithmetic Operator on two operands a and bthe result type is

Syntax:
max(int,type of a,type of b)

Example:

  • double+float=double max(int,double,float)
  • double+char=double
  • short+byte=int max(int,short,byte)
  • byte*short=int
  • int+long=long
  • byte+long=long

Infinity

In the integral arithmetic,there is no way to represent Infinity hence “division/0” is always ” ArithmeticException” in integral arithmetic.
Example:

System.out.println(10/0);// ArithmeticException/zero

But in the case of floating point arithmetic there is a way to represent Infinity

Float and Double classes contains the following constants.

  1. POSITIVE_INFINITY
  2. NEGATIVE_INFINITY

Hence division by zero is not “ArithmeticException” in floating point arithmetic.

Example:

  System.out.println(10.0/0); //infinity 
  System.out.println(10/0.);  //infinity 
  System.out.println(-10.0/0);//-infinity