-
Notifications
You must be signed in to change notification settings - Fork 25
/
RomanNumeralsEx.java
46 lines (35 loc) · 978 Bytes
/
RomanNumeralsEx.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
package com.zetcode;
import java.util.HashMap;
import java.util.Map;
public class RomanNumeralsEx {
public static void main(String[] args) {
Map<Integer, String> table = new HashMap<>() {{
put(1, "I");
put(2, "II");
put(3, "III");
put(4, "IV");
put(5, "V");
put(6, "VI");
put(7, "VII");
put(8, "VIII");
put(9, "IX");
put(10, "X");
put(20, "XX");
put(30, "XXX");
put(40, "XL");
put(50, "L");
put(60, "LX");
put(70, "LXX");
put(80, "LXXX");
put(90, "XC");
}};
int val = 87;
if (table.containsKey(val)) {
System.out.println(table.get(val));
} else {
int rem = val % 10;
int num = val - rem;
System.out.println(table.get(num) + table.get(rem));
}
}
}