-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operators.java
39 lines (34 loc) · 1.05 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
/*
TODO: Use of all Operators
*/
class Operators
{
public static void main(String[] args)
{
int x = 10, y = 15;
System.out.println("x="+ x);
System.out.println("x++="+ x++);
System.out.println("++x="+ ++x);
System.out.println(x++ + ++x);
System.out.println("~x="+ ~x);
System.out.println(x + y);
System.out.println(x * y);
System.out.println(x - y);
System.out.println(x / y);
System.out.println(x % y);
System.out.println(x << 2);
System.out.println(x >> 3);
System.out.println(20 >>> 2); // Works ">>>" same for positive numbers
System.out.println(-20 >>> 2); // Changes parity bit (MSB) to 0
System.out.println(x > y || x < y); // Logical Operator
System.out.println(x < y && x < y); // Logical Operator
System.out.println("x="+ x);
System.out.println("y="+ y);
System.out.println(x < y & x++ < y); // Bitwise Operator
System.out.println(x < y | x++ < y); // Bitwise Operator
int min = (x < y)? x:y; // Ternary Operator
System.out.println(min);
x+= 4;
System.out.println("x="+x); // Assigment Operator
}
}