5.2 Operators in Java
5.2 Operators in Java
5.2 Operators in Java
There are many types of operators in Java which are given below:
o Unary Operator,
o Arithmetic Operator,
o Shift Operator,
o Relational Operator,
o Bitwise Operator,
o Logical Operator,
o Ternary Operator and
o Assignment Operator.
Arithmetic multiplicative * / %
additive + -
equality == !=
bitwise exclusive ^
OR
bitwise inclusive |
OR
logical OR ||
Ternary ternary ? :
Output:
10
12
12
10
Output:
22
21
Output:
-11
9
false
true
Output:
15
5
50
2
0
Output:
ADVERTISEMENT
21
Output:
40
80
80
240
1. public OperatorExample{
2. public static void main(String args[]){
3. System.out.println(10>>2);//10/2^2=10/4=2
4. System.out.println(20>>2);//20/2^2=20/4=5
5. System.out.println(20>>3);//20/2^3=20/8=2
6. }}
Output:
2
5
2
Output:
5
5
-5
1073741819
The bitwise & operator always checks both conditions whether first
condition is true or false.
ADVERTISEMENT
ADVERTISEMENT
Output:
false
false
Output:
false
10
false
11
ADVERTISEMENT
ADVERTISEMENT
Output:
true
true
true
10
true
11
Output:
Another Example:
Output:
Output:
14
16
Output:
13
9
18
9
Output:
Compile time error
Output:
20