-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operators.java
73 lines (51 loc) · 1.93 KB
/
Operators.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
class Operators{
public static void main(String args[]){
// ####### ARITHMETIC OPERATORS ########## //
int num1 = 7;
int num2 = 5;
// now i can perform some operation
// and we can save the result
int result = num1 + num2;
System.out.println(result);
// +,-,/,%,* - arithmetic operators.
result = num1 % num2; // remainder operator
System.out.println(result);
// num1 = num1 + 2;// shortcut
// num1+=2; // add myself 2
// num1++; // adds 1 to previous value of num1 are stores it in num1
// // we can also decrement // post increment
// num1--; // subtracts 1 from previous value of num2 ...
// // we can aslo do ++num1
// ++num1; // pre-increment,
// --num1;// pre-decrement
// lets take example
result = ++num1; // increment first then assign value
System.out.println(result); // 8
result = num1++; // stores num1 first then increments num1
System.out.println(result);// we should get 9 but here we got 8
// System.out.println(num1);
// ####### RELATIONAL OPERATORS ########## //
// ==,!=,>=,<=,>,<
boolean res = num1<num2;
System.out.println(res);
res = num1>num2;
System.out.println(res);
res = num1==num2;
System.out.println(res);
res = num1>=num2;
System.out.println(res);
// ####### LOGICAL OPERATORS ########## //
// AND, OR, NOT, XOR[later]
// &,(&&) - |.(||) - !
boolean x = true;
boolean y = false;
res = x || y;
System.out.println(res);
res = x && y;
System.out.println(res);
res = !(x);
System.out.println(res);
res = x || y && num1 > num2;
System.out.println(res);
}
}