-
Notifications
You must be signed in to change notification settings - Fork 0
/
operatr.java
77 lines (57 loc) · 3.28 KB
/
operatr.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class operatr{
public static void main(String[] a){
// Different Types of Operators
// Arithmetic Operator
int num1 = 12, num2 = 6;
System.out.println("First Number : " + num1);
System.out.println("Second Number : " + num2);
System.out.println("\nArithmetic Operators : ");
System.out.println("Addition : " + (num1 + num2));
System.out.println("Subtraction : " + (num1 - num2));
System.out.println("Multiplication : " + (num1 * num2));
System.out.println("Divison : " + (num1 / num2));
System.out.println("Modulus Division : " + (num1 % num2));
// Unary Operators
System.out.println("\nUnary Operators : ");
System.out.println("Post Increment to First Number : " + num1++);
System.out.println("Pre Increment to Second Number : " + ++num2);
System.out.println("Post Decrement to First Number : " + num1--);
System.out.println("Pre Decrement to Second Number : " + --num2);
// Assignment Operator
System.out.println("\nAssignment Operators : ");
System.out.println("Assignment Addition : " + (num1 += 2));
System.out.println("Assignment Subtraction : " + (num2 -= 2));
System.out.println("Assignment Multiplication : " + (num2 *= 2));
System.out.println("Assignment Divison : " + (num2 /= 2));
// Relational Operator
System.out.println("\nRelational Operators : ");
System.out.println("Checking Equality : " + (num1 == num2));
System.out.println("Checking if first number is greater than second one : " + (num1 > num2));
System.out.println("Checking if second number is greater than first one : " + (num1 < num2));
System.out.println("Checking if first number is greater than or equal to second number : " + (num1 >= num2));
System.out.println("Checking if second number is greater than or equalt to first number : " + (num1 <= num2));
System.out.println("Checking if the numbers are unequal : " + (num1 != num2));
// Some Boolean Value
boolean bool1 = true;
boolean bool2 = false;
// Logical Operator
System.out.println("\nLogical Operators : ");
System.out.println("Logical OR || operator : " + (bool1 && bool2));
System.out.println("Logical AND && operator : " + (bool1 || bool2));
System.out.println("Logical NOT ! operator : " + (!bool1));
// Ternary Operator
System.out.println("\nTernary Operator : ");
System.out.println("Checking if the first number is greater than second one : " + ((num1 > num2) ? true : false));
// Bitwise Operator
System.out.println("\nBitwise Operators : ");
System.out.println("Bitwise & AND Operator : " + (num1 & num2));
System.out.println("Bitwise | OR Operator : " + (num1 | num2));
System.out.println("Bitwise ^ NOT Operator : " + (num1 ^ num2));
System.out.println("Bitwise ~ Operator : " + (~num1));
// Bitwise Shift Operator
System.out.println("\nBitwise Shift Operator : ");
System.out.println("Bitwise << Operator : " + (num1 << 2));
System.out.println("Bitwise >> Operator : " + (num1 >> 1));
System.out.println("Bitwise >>> Operator : " + (num2 >>> 2));
}
}