-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterger_to_Roman.java
More file actions
51 lines (42 loc) · 1.16 KB
/
Interger_to_Roman.java
File metadata and controls
51 lines (42 loc) · 1.16 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
47
48
49
50
51
import java.util.HashMap;
import java.util.Map;
/**
* Created by Lumpy on 17.06.2016.
*/
public class Interger_to_Roman {
public static void main(String[] args) {
System.out.println(toRoman(99));
}
public static String toRoman(int a){
String output = "";
Map<Integer, String> map = new HashMap<>();
map.put(1, "I");
map.put(4, "IV");
map.put(5, "V");
map.put(9, "IX");
map.put(10, "X");
map.put(50, "L");
map.put(100, "C");
map.put(500, "D");
map.put(1000, "M");
Map<Integer, Integer> map2 = new HashMap<>();
map2.put(0,1);
map2.put(1,4);
map2.put(2,5 );
map2.put(3,9);
map2.put(4,10 );
map2.put(5,50 );
map2.put(6,100 );
map2.put(7,500 );
map2.put(8,1000);
for(int i = map2.size()-1; i > -1; i--) {
if (a / map2.get(i) > 0) {
int test = a / map2.get(i);
for (int x = 0; x < test; x++)
output+=(map.get(map2.get(i)));
a -= map2.get(i)*test;
}
}
return output;
}
}