Arithmetic Operators in Java

Notes:

Arithmetic Operators in Java Programming Language:

- Java provides 5 arithmetic operators to perform arithmetic operations. They are

+: Addition Operator : sum of two numbers
- : Subtraction Operator : difference between two numbers
*: Multiplication Operator : product of two numbers
/: Division Operator : quotient of a complete division operation
%: Modulus Operator : remainder of a first division operation

Example Code:

package arithmeticoperatorsdemo;

public class ArithmeticOperatorsDemo
{
public static void main(String[] args)
{
System.out.println(2+2); // 4
System.out.println(5+2); // 7

System.out.println(5-2); // 3
System.out.println(10-2); // 8

System.out.println(5*2); // 10
System.out.println(10*2); // 20

System.out.println(10/2); // 5
System.out.println(10%2); // 0

System.out.println(11/(float)2); // 5.5
System.out.println(11%2); // 1

System.out.println(0/100); // 0
// System.out.println(100/0); // division by zero error

System.out.println('A' + 'A'); // 130
System.out.println('B' - 'A'); // 1

System.out.println( 2 + 2 ); // 4
System.out.println( "Hello " + "world" ); // Hello world
System.out.println( "Hello " + 2 ); // Hello 2
System.out.println( true + " world" ); // true world

}
}