More Operator

More Operator


Java divides the operators into the following groups:

Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Bitwise operators

Operator

Name

Description

Example

+

Addition

Adds together two values

x + y

-

Subtraction

Subtracts one value from another

x - y

*

Multiplication

Multiplies two values

x * y

/

Division

Divides one value by another

x / y

%

Modulus

Returns the division remainder

x % y

++

Increment

Increases the value of a variable by 1

++x

--

Decrement

Decreases the value of a variable by 1

--x

Assignment Operators

Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator (=) to assign the value 10 to a variable called x:
Example

int x = 10;

The addition assignment operator (+=) adds a value to a variable:
Example

int x = 10; x += 5;

Comparison Operators

Comparison operators are used to compare two values:

Operator

Name

Example

==

Equal to

x == y

!=

Not equal

x != y

>

Greater than

x > y

<

Less than

x < y

>=

Greater than or equal to

x >= y

<=

Less than or equal to

x <= y

 Java Logical Operators

Logical operators are used to determine the logic between variables or values:

Operator

Name

Description

Example

&& 

Logical and

Returns true if both statements are true

x < 5 &&  x < 10

|| 

Logical or

Returns true if one of the statements is true

x < 5 || x < 4

!

Logical not

Reverse the result, returns false if the result is true

!(x < 5 && x < 10)