Skip to content

Instantly share code, notes, and snippets.

@theboreddev
Created June 11, 2020 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theboreddev/2bb58e73ee28524d0b0ce1e742bf2377 to your computer and use it in GitHub Desktop.
Save theboreddev/2bb58e73ee28524d0b0ce1e742bf2377 to your computer and use it in GitHub Desktop.
findLowerKey
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