MY PROGRAMMING PARADISE
Operators in java:
Operators are the symbols that tell the computer to execute certain mathematical or logical operations. A mathematical or logical expression is generally formed with the help of an operator.
There are many types of operators in java which are given below:
1. Arithmetic operator
2. Increment and Decrement operator
3. Assignment Operator
4. Relational Operator
5. Logical Operator
6. Bitwise Operator
7. Ternary Operator
Assume variable A holds 20 and variable B holds 30 then:
Operator type | Operator | Description | Example |
Arithmetic operator
| + | Adds two operands | A+B= 50 |
- | Subtracts second operand from the first | A-B=- 10 | |
* | Multiply both operands | A*B= 600 | |
/ | Divide numerator by denominator | B/A= 3 | |
% | Modulus Operator and remainder of after an integer division | B%A= 10 | |
Unary or Increment and Decrement operator | ++ | Increment operator, increases integer value by one | A++ will give 21 |
-- | Decrement operator, decreases integer value by one | A-- will give 19 | |
Assignment Operator
| = | Simple assignment operator, Assigns values from right side operands to left side operand | C = A + B will assign value of A + B into C |
+= | Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand | C += A is equivalent to C = C + A | |
-= | Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand | C -= A is equivalent to C = C - A | |
*= | Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand | C *= A is equivalent to C = C * A | |
/= | Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand | C /= A is equivalent to C = C / A | |
%= | Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand | C %= A is equivalent to C = C % A | |
Relational Operator
| > | Checks if the value of left operand is greater than the value of Right operand, if yes then condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right Operand, if yes then condition becomes true. | (A < B) 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. | (A >= B) is not 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. | (A <= B) is true. | |
== | Checks if the value of two operands is equal or not, if yes then Condition becomes true. | (A == B) is not true. | |
!= | Checks if the value of two operands is equal or not, if values are not equal then condition becomes true | (A != B) is true. |
Operator type | Operator | Description | Example |
Logical Operator | && | Returns true when both conditions are true. |
|
|| | Returns true if at least one condition is true. | ||
Bitwise Operator | & | It returns 1 if and only if both bits are 1, else returns 0. | |
^ | It returns 0 if both bits are the same, else returns 1. | ||
| | It returns 1 if either of the bit is 1, else returns 0. | ||
Ternary Operator | ?: | Conditional Expression |
Video Link:) Click here
Comments
Post a Comment