forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpr1.java
More file actions
137 lines (93 loc) · 2.07 KB
/
Expr1.java
File metadata and controls
137 lines (93 loc) · 2.07 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
class Expr1 {
public static void main(String[] args) {
int x = 0;
System.out.println(x);
// assign
x = 42;
System.out.println(x);
// plus assign
x += 33;
System.out.println(x);
// minus assign
x -= 21;
System.out.println(x);
// star assign
x *= 17;
System.out.println(x);
// div assign
x /= 4;
System.out.println(x);
// and assign
x &= 3;
System.out.println(x);
// and assign
x = 444;
x &= 0x0bc;
System.out.println(x);
// or assign
x = 444;
x |= 0x01;
System.out.println(x);
// mod assign
x = 13;
x %= 5;
System.out.println(x);
// bit shift right assign
// shift right assign
// shift left assign
// question
x = 3;
System.out.println(x==3 ? 1 : 0);
System.out.println(x!=3 ? 1 : 0);
String y = new String();
System.out.println(y instanceof String ? "object" : "notobject");
System.out.println(x <= 0 ? 1 : 0);
System.out.println(x >= 0 ? 1 : 0);
// logical or
System.out.println(1 < 3 || 3 > 1 ? 1 : 0);
// logical and
System.out.println(1 < 3 && 3 > 1 ? 1 : 0);
// or
System.out.println(4 | 2);
// xor
System.out.println(4 ^ 3);
// and
System.out.println(3 & 2);
// equal
System.out.println(3 == 3 ? 1 : 0);
System.out.println(3 == 4 ? 1 : 0);
// not equal
System.out.println(3 != 3 ? 1 : 0);
System.out.println(3 != 4 ? 1 : 0);
System.out.println(44 >> 3);
System.out.println(44 > 3 ? 1 : 0);
System.out.println(44 << 3);
System.out.println(44 < 3 ? 1 : 0);
x = 33;
System.out.println(x+1);
System.out.println(x-1);
System.out.println(x*x*x);
System.out.println(x/2);
System.out.println(x%2);
x = -33;
System.out.println(-x);
System.out.println(+x);
// NB: these tests side-step the issue of using pre/post inc in
// expressions
x = 55;
++x;
System.out.println(x);
--x;
System.out.println(x);
x++;
System.out.println(x);
x--;
System.out.println(x);
x = 55;
System.out.println(~x);
System.out.println(!false ? 1 : 0);
System.out.println( (Integer) x );
x = 7;
System.out.println(x >>> 1);
}
}