Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class RomanNumerals {
private static final NavigableMap<Integer, String> ROMAN_NUMERALS = new TreeMap<>() {
put(1, "I");
put(5, "V");
put(10, "X");
put(50, "L");
put(100, "C");
put(500, "D");
put(1000, "M");
public static String convert(int number) {
final String result = ROMAN_NUMERALS.get(number);
return result != null ? result : ROMAN_NUMERALS.get(ROMAN_NUMERALS.lowerKey(number));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment