EpicEnchants/core/src/main/java/com/songoda/epicenchants/utils/single/RomanNumber.java

32 lines
712 B
Java
Raw Normal View History

2019-02-19 14:23:20 +01:00
package com.songoda.epicenchants.utils.single;
import java.util.TreeMap;
public class RomanNumber {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>() {{
put(1000, "M");
put(900, "CM");
put(500, "D");
put(400, "CD");
put(100, "C");
put(90, "XC");
put(50, "L");
put(40, "XL");
put(10, "X");
put(9, "IX");
put(5, "V");
put(4, "IV");
put(1, "I");
}};
public static String toRoman(int number) {
int l = map.floorKey(number);
if (number == l) {
return map.get(number);
}
return map.get(l) + toRoman(number - l);
2019-02-19 14:23:20 +01:00
}
}