Professional Documents
Culture Documents
A990689351 - 21789 - 9 - 2019 - 04. Operators
A990689351 - 21789 - 9 - 2019 - 04. Operators
• Introduction
• Assignment Operator
• Arithmetic Operator
• Relational Operator
• Bitwise Operator
• Conditional Operator
• Type Comparison Operator
• Unary Operator
Introduction
• 1. Unary Operator,
• 2. Arithmetic Operator,
• 3. Shift Operator,
• 4. Relational Operator,
• 5. Bitwise Operator,
• 6. Logical Operator,
• 7.Ternary Operator and
• 8. Assignment Operator.
Unary Operators
The unary operators require only one operand.
Operator Description
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator
Java Arithmetic Operator Example
• class OperatorExample
• {
• public static void main(String args[])
• {
• int a=10;
• int b=5;
• System.out.println(a+b); //15
• System.out.println(a-b); //5
• System.out.println(a*b); //50
• System.out.println(a/b); //2
• System.out.println(a%b); //0
• }
• }
Java Arithmetic Operator Example:
Expression
• class OperatorExample
• {
• public static void main(String args[])
• {
• System.out.println(10*10/5+3-1*4/2);
• }
• } Output:
• 21
Shift Operators
• Java Left Shift Operator<<
• Example:
– 11111111 11111111 11111111 11111111 –1 in
binary as an int
– >>>24
– 00000000 00000000 00000000 11111111 255 in
binary as an int
Java AND Operator
== equal to
!= not equal to
System.out.println(34<<3);
System.out.println(-34>>3);
System.out.println(-34>>>3);
Brainstorming 2
int x = 10, y = 5;
while(x- - > 7 || + + y < 8 )
System.out.print(x);
System.out.print(y);
A. 95
B. 67
C. 78
D. 48
E. 77
F. N.O.T
Brainstorming 3
System.out.print(2>1||4>3?false:true);
class X{}
class Y extends X{}
class Z extends Y{}
X x1 = new Y();
Y y1 = new Z();
Y y2 = new Y();
System.out.println( x1 instanceof X);
System.out.println( x1 instanceof Z);
System.out.println( y1 instanceof Z);
System.out.println( y2 instanceof X);
Brainstorming 4
System.out.print(2>1||4>3?false:true);