-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comparisons.java
82 lines (76 loc) · 1.65 KB
/
Comparisons.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
74
75
76
77
78
79
80
81
82
public final class Comparisons {
static int main() {
var a = new Comparisons();
var b = new Comparisons();
if (a == a) {
printOk(0);
}
if (a != b) {
printOk(1);
}
compare(1);
compareZero(0);
compareZero(1);
compareLong(0);
compareLong(1);
compareLong(-1);
compareNull(null);
compareNull(a);
return 0;
}
private static void compare(int value) {
if (value == 1) {
printOk(2);
}
if (value != 2) {
printOk(3);
}
if (value < 2) {
printOk(4);
}
if (2 > value) {
printOk(5);
}
}
private static void compareZero(int value) {
if (value == 0) {
printOk(6);
}
if (value != 0) {
printOk(7);
}
if (value < 0) {
printOk(8);
}
if (value >= 0) {
printOk(9);
}
if (value <= 0) {
printOk(10);
}
}
private static void compareLong(long l) {
if (l == 0) {
printOk(11);
}
if (l > 0) {
printOk(12);
}
if (l < 0) {
printOk(13);
}
}
private static void compareNull(Comparisons o) {
if (o == null) {
printOk(14);
}
if (o != null) {
printOk(15);
}
}
private static void printOk(int count) {
var c = (byte) ('0' + count);
puts(new byte[]{'O', 'K', '#', c, '\0'});
}
static native int puts(byte[] str);
}