-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntToR.java
More file actions
31 lines (26 loc) · 779 Bytes
/
IntToR.java
File metadata and controls
31 lines (26 loc) · 779 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
class IntToR{
public String IntToRoman(int num) {
Map<String, Integer> mp = new LinkedHashMap<>();
mp.put("M", 1000);
mp.put("CM",900);
mp.put("D", 500);
mp.put("CD", 400);
mp.put("C", 100);
mp.put("XC", 90);
mp.put("L", 50);
mp.put("XL", 40);
mp.put("X", 10);
mp.put("IX", 9);
mp.put("V", 5);
mp.put("IV", 4);
mp.put("I", 1);
String sb = "";
for(Map.Entry<String, Integer> entry : mp.entrySet()) {
while(num >= entry.getValue()) {
num = num - entry.getValue();
sb=sb + entry.getKey();
}
}
return sb.toString();
}
}