Monday, October 14, 2013

Basic Operators

Insurance Loans Mortgage Attorney Credit Lawyer Donate Degree Hosting Claim Conference Call Trading Software Recovery Transfer Gas/Electricity Classes Rehab Treatment Cord Blood

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:


  • Arithmetic Operators
  • Relational Operators
  • Bitwise Operators
  • Logical Operators
  • Assignment Operators
  • Misc Operators

The Arithmetic Operators :


Operator Description Example
+ Addition - Adds values on either side of the operator 10 + 10 = 20
- Subtraction - Subtracts right hand operand from left hand operand 20 - 10 = 10
* Multiplication - Multiplies values on either side of the operator 2 * 2 = 4
/ Division - Divides left hand operand by right hand operand 10 / 2 = 5
% Modulus - Divides left hand operand by right hand operand and
returns remainder
10 % 2 = 0
++ Increment - Increases the value of operand by 1 1++ Given 2
-- Decrement - Decreases the value of operand by 1 2-- Given 1

The Relational Operators:

There are following relational operators supported by Java language




Operator Description Example
== Checks if the values of two operands are equal or not, if yes then
condition becomes true.
10 == 10 is true
10 == 20 is false
!= Checks if the values of two operands are equal or not, if values are not equal then
condition becomes true
10 != 10 is false
10 != 20 is true
> Checks if the value of left operand is greater than the value of right operand, if yes then
condition becomes true.
2 > 1 is true
4 > 2 is false
< Checks if the value of left operand is less than the value of right operand, if yes then
condition becomes true.
10 < 2 is false
2 < 10 is true
>= Checks if the value of left operand is greater than or equal to the value of right operand,
if yes then condition becomes true.
10>=10 is true
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then
condition becomes true.
10<=10 is true

No comments:

Post a Comment