Tutorials

# Arithmetic Operators in java 7

In this section you will learn about the Arithmetic operators. This is one type of operators.

In this section you will learn about the Arithmetic operators. This is one type of operators.

## Arithmetic Operators in java 7

In this section you will learn about the Arithmetic operators. This is one type of operators.

Arithmetic Operators :

Arithmetic operators are the most commonly used operator in our expressions. We use these kind of operators in our mathematical expression. They work same as we use in algebra.

Arithmetic operators are used to perform addition, subtraction, multiplication, and division. Suppose X and Y are two numeric variables.

+ (additive operator) this operator is used for adding two numbers as well as used for String concatenation. (X+Y)

- (Subtraction operator) This operator is used for subtracting the values. (X-Y)

* (Multiplication operator) It is used to multiply values. (X*Y)

/ (Division operator) This operator is used where you want to divide some values. (X/Y)

% (Remainder operator) - This is also called modulus operator. It returns remainder. (X%Y)

Other arithmetic operators -

++ (increment) - This operator increments the value by 1. (X++)
-- (decrement) -
This operator decrements the value by 1. (X--)

Example :

```package operator;

class ArithmaticOperator {
public static void main(String[] args) {
int x = 100;
int y = 20;
int sum, sub, mul, mod;
double div;

sum = x + y; // using Additive operator
sub = x - y; // using Subtraction operator
mul = x * y; // using Multiplication operator
div = x / y; // using Division operator
mod = x / y; // using Remainder operator

System.out.println("Value of x = " + x);
System.out.println("Value of y = " + y);
System.out.println("Sum of x and y using Additive operator = " + sum);
System.out.println("Subtraction of x and y using Subtraction operator = "
+ sub);
System.out.println("Multiplication of x and y using Multiplication operator = "
+ mul);
System.out.println("Division of x and y using Additive operator = "
+ div);
System.out.println("Remainder of x and y using Remainder operator = "
+ mod);

x++; // increment operator
y--; // decrement operator

System.out.println("Incrementing x by using increment operator = " + x);
System.out.println("Decrementing y by using decrement operator = " + y);
}
}
```

Output :

```Value of x = 100
Value of y = 20
Sum of x and y using Additive operator = 120
Subtraction of x and y using Subtraction operator = 80
Multiplication of x and y using Multiplication operator = 2000
Division of x and y using Additive operator = 5.0
Remainder of x and y using Remainder operator = 5
Incrementing x by using increment operator = 101
Decrementing y by using decrement operator = 19
```