-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh2_Operator.java
More file actions
56 lines (49 loc) · 1.26 KB
/
Ch2_Operator.java
File metadata and controls
56 lines (49 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class Ch2_Operator{
public static void main(String[] args) {
// 1. Arithmetic Operation
// int a = 3;
// int b = 3 + a;
// int b = 6 * a;
// int b = 6 - a;
// int b = 6 / 3;
// System.out.println(20 % 3); // Modulue: % --> It gives the result of remainder of div.
// System.out.println(b);
// 2. Assignment Operator
// int a = 6;
// a += 3;
// a -= 3;
// a *= 2;
// a /= 2;
// System.out.println(a);
// 3. Conditional Operartor
// System.out.println(20 == 3);
// System.out.println(20 == 20);
// System.out.println(20 >= 2);
// System.out.println(20 >= 50);
// System.out.println(20 <= 3);
// System.out.println(20 <= 78);
// 4. Logical Operator
// int a = 4;
// int b = 3;
// System.out.println(20 == 20 || 18 <= 2);
// System.out.println(20 == 20 && 18 >= 8);
// System.out.println(a % 2 == 0);
// System.out.println(b % 2 != 0);
// Bitwise Operator
System.out.println(2 & 2);
System.out.println(2 | 2);
// Anding or Multiply in binary
// 10(2)
// & or . 11(3)
// -----------
// ans-> 10(2)
// Adding or sum in binary
// 10(2)
// | or + 11(3)
// ---------
// carry-> 1 01(1)
// +1
// --------
// ans -> 10(2)
}
}