-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperatorsExample.java
More file actions
60 lines (46 loc) · 1.73 KB
/
Copy pathOperatorsExample.java
File metadata and controls
60 lines (46 loc) · 1.73 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
public class OperatorsExample {
public static void main(String[] args) {
int a = 10;
int b = 5;
// Arithmetic Operators
System.out.println("Addition: " + (a + b));
System.out.println("Subtraction: " + (a - b));
System.out.println("Multiplication: " + (a * b));
System.out.println("Division: " + (a / b));
System.out.println("Modulus: " + (a % b));
// Unary Operators
System.out.println("Post Increment: " + (a++));
System.out.println("Pre Increment: " + (++a));
System.out.println("Post Decrement: " + (b--));
System.out.println("Pre Decrement: " + (--b));
// Assignment Operators
int x = 10;
x += 5;
System.out.println("x += 5 : " + x);
x *= 2;
System.out.println("x *= 2 : " + x);
// Relational Operators
System.out.println("a > b : " + (a > b));
System.out.println("a < b : " + (a < b));
System.out.println("a == b : " + (a == b));
System.out.println("a != b : " + (a != b));
// Logical Operators
boolean p = true;
boolean q = false;
System.out.println("p && q : " + (p && q));
System.out.println("p || q : " + (p || q));
System.out.println("!p : " + (!p));
// Ternary Operator
int max = (a > b) ? a : b;
System.out.println("Largest number: " + max);
// Bitwise Operators
int c = 6;
int d = 3;
System.out.println("c & d : " + (c & d));
System.out.println("c | d : " + (c | d));
System.out.println("c ^ d : " + (c ^ d));
// instanceof Operator
String str = "Hello";
System.out.println(str instanceof String);
}
}