-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy patharithmetic.java
More file actions
32 lines (22 loc) · 764 Bytes
/
arithmetic.java
File metadata and controls
32 lines (22 loc) · 764 Bytes
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
import java.util.*;
public class arithmetic {
public static String Base8toBase16(String base8 , boolean leadingZeroes) {
int base10 = Integer.parseInt(base8 , 8);
String base16 = Integer.toString(base10 , 16).toUpperCase();
// Formatting
base16 = "XXX" + base16;
base16 = base16.substring(base16.length() - 3);
return base16.replace("X" , leadingZeroes ? "0" : "");
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String base8 = scan.nextLine();
while (base8.length() % 4 != 0)
base8 = "0" + base8;
String lead = base8.substring(0 , 4);
System.out.print(Base8toBase16(lead , false));
for (int i = 4; i < base8.length(); i += 4)
System.out.print(Base8toBase16(base8.substring(i , i + 4) , true));
scan.close();
}
}