Repository navigation
Expand file tree
/
Copy pathArithmeticOperations.java
More file actions
62 lines (57 loc) · 2.17 KB
/
Copy pathArithmeticOperations.java
File metadata and controls
62 lines (57 loc) · 2.17 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
public class ArithmeticOperations {
public static void main(String[] args)
{
int a = 10, b = 5;
char operator = '+';
switch (operator)
{
case '+':
System.out.println("Addition: " + (a + b));
break;
case '-':
System.out.println("Subtraction: " + (a - b));
break;
case '*':
System.out.println("Multiplication: " + (a * b));
break;
case '/':
if (b != 0) {
System.out.println("Division: " + (a / b));
} else {
System.out.println("Division by zero is not allowed.");
}
break;
case '%':
System.out.println("Modulus: " + (a % b));
break;
default:
System.out.println("Invalid operator");
}
boolean x = true, y = false;
System.out.println("Logical AND: " + (x && y));
System.out.println("Logical OR: " + (x || y));
System.out.println("Logical NOT: " + (!x));
System.out.println("Is a equal to b? " + (a == b));
System.out.println("Is a not equal to b? " + (a != b));
System.out.println("Is a greater than b? " + (a > b));
System.out.println("Is a less than or equal to b? " + (a <= b));
int c = 20;
c += 5;
System.out.println("After addition assignment, c: " + c);
c -= 3;
System.out.println("After subtraction assignment, c: " + c);
c *= 2;
System.out.println("After multiplication assignment, c: " + c);
c /= 4;
System.out.println("After division assignment, c: " + c);
c %= 3;
System.out.println("After modulus assignment, c: " + c);
int d = 6, e = 3;
System.out.println("Bitwise AND: " + (d & e));
System.out.println("Bitwise OR: " + (d | e));
System.out.println("Bitwise XOR: " + (d ^ e));
System.out.println("Bitwise Complement: " + (~d));
System.out.println("Left Shift: " + (d << 1));
System.out.println("Right Shift: " + (d >> 1));
}
}