Repository navigation
Expand file tree
/
Copy pathOperators.java
More file actions
74 lines (58 loc) · 2.89 KB
/
Copy pathOperators.java
File metadata and controls
74 lines (58 loc) · 2.89 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public class Operators {
public static void main(String args[]){
//Arithmetic Operators
int a = 11;
int b = 5;
int p;
System.out.println("Addition :"+(a+b));
System.out.println("Subtraction :"+(a-b));
System.out.println("Multiplication :"+(a*b));
System.out.println("Divsion :"+(a/b));
System.out.println("Modulus :"+(a%b));
System.out.println("-------------------------------------------------------");
// Relational Operator [Returns True or False]
System.out.println("== :"+(a==b));
System.out.println("!= :"+(a!=b));
System.out.println("> :"+(a>b));
System.out.println("< :"+(a<b));
System.out.println(">= :"+(a>=b));
System.out.println("<= :"+(a<=b));
System.out.println("-------------------------------------------------------");
//Logical Operators
System.out.println("&& :"+(true && false));
System.out.println("||:"+(true||false));
System.out.println("! :"+(!true));
System.out.println("-------------------------------------------------------");
//Bitwise Operator [Works at Binary Level]
System.out.println("AND :"+(a&b));
System.out.println("OR :"+(a|b));
System.out.println("XOR :"+(a^b));
System.out.println("NOT :"+(~a));
System.out.println("Leftshift :"+(a << 1));
System.out.println("Rightshift :"+(a >> 1));
System.out.println("-------------------------------------------------------");
//Unary Operator
System.out.println("+ :"+(+a));
System.out.println("- :"+(-a));
System.out.println("++ :"+(++a)); // Pre Increment : increments first, then uses the value.
System.out.println("++ :"+(a++)); // Post Increment : uses the value first, then increments.
System.out.println("-- :"+(--a)); // Pre Decrement : decrements first, then uses the value.
System.out.println("++ :"+(a--)); // Post Decrement : uses the value first, then decrements.
System.out.println("-------------------------------------------------------");
//Assignment Operator[Works on single Operand]
System.out.println("= :"+(p = 10));
System.out.println("+= :"+(p += 5));
System.out.println("-= :"+(p-=2));
System.out.println("*= :"+(p*=10));
System.out.println("/= :"+(p/=2));
System.out.println("%= :"+(p%=5));
System.out.println("-------------------------------------------------------");
//Ternary Operator [Shortcut if-else]
String result = (a >= 5) ? "Greater" : "Smaller";
System.out.println(result);
System.out.println("-------------------------------------------------------");
//InstanceOf Operator [object belongs to a particular class]
String str = "Hello";
System.out.println(str instanceof String);
}
}