- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
46 lines (39 loc) · 1.08 KB
/
Copy pathMain.java
File metadata and controls
46 lines (39 loc) · 1.08 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
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.io.StringReader;
importjava.util.regex.Pattern;
publicclassMain {
publicstaticvoidmain(String[] args) throwsIOException {
BufferedReaderreader;
if (args.length > 0) {
reader = newBufferedReader(newInputStreamReader(System.in));
} else {
reader = newBufferedReader(newStringReader(
"""
1101111
"""
));
}
for(;;) {
Stringline = reader.readLine();
if (null == line) {
break;
}
Stringconverted = toHex(line);
System.out.println(converted);
}
}
publicstaticStringtoHex(Stringbinary) {
if (binary.length() % 4 != 0) {
// append zeros
}
if (!Pattern.matches("[01]*", binary)) {
returnnull;
}
return"1";
}
publicstaticStringtoBinary(Stringhex) {
return"01";
}
}