-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.java
More file actions
66 lines (49 loc) · 1.88 KB
/
Copy pathOperators.java
File metadata and controls
66 lines (49 loc) · 1.88 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
package basics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Arithmetic, relational, logical, assignment, and ternary operators.
*/
public class Operators {
private static final Logger logger = LoggerFactory.getLogger(Operators.class);
public static void main(){
// Arithmetic Operators
logger.info("--- Arithmetic Operators ---");
int a = 10;
int b = 3;
logger.info("a + b = {}", a + b);
logger.info("a - b = {}", a - b);
logger.info("a * b = {}", a * b);
logger.info("a / b = {} (integer division)", a / b);
logger.info("a % b = {} (modulo/remainder)", a % b);
// Increment and Decrement Operators
logger.info("--- Increment and Decrement Operators ---");
int counter = 5;
logger.info("counter++ = {} | then counter = {}", counter++, counter);
logger.info("++counter = {}", ++counter);
// Relational Operators
logger.info("--- Relational Operators ---");
logger.info("a > b: {}", a > b);
logger.info("a == b: {}", a == b);
logger.info("a != b: {}", a != b);
// Logical Operators
logger.info("--- Logical Operators ---");
boolean p = true;
boolean q = false;
logger.info("p && q = {}", p && q);
logger.info("p || q = {}", p || q);
logger.info("!p = {}", !p);
// Compound Assignment
logger.info("--- Compound Assignment ---");
int x = 10;
x += 5; logger.info("x += 5 -> {}", x);
x -= 3; logger.info("x -= 3 -> {}", x);
x *= 2; logger.info("x *= 2 -> {}", x);
x /= 4; logger.info("x /= 4 -> {}", x);
// Ternary Operator
logger.info("--- Ternary Operator ---");
int number = 7;
String result = (number % 2 == 0) ? "Even" : "Odd";
logger.info("{} is {}", number, result);
}
}