Java int to roman
import java.util.TreeMap;
public class RomanNumber {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
static {
map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
map.put(400, "CD");
map.put(100, "C");
map.put(90, "XC");
map.put(50, "L");
map.put(40, "XL");
map.put(10, "X");
map.put(9, "IX");
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");
}
public final static String toRoman(int number) {
int l = map.floorKey(number);
if ( number == l ) {
return map.get(number);
}
return map.get(l) + toRoman(number-l);
}
}
Also in Java:
- 2 decimal places print format JAVA
- java initialize string array
- how to declare array java
- java parse xml string
- thread sleep java
- loop java
- java type casting
- jquery set data attribute value
- JavaFX onMouseEntered
- entre clavier java
- tower of hanoi program in java using recursion
- java read string input
- length of string java
- java get annotation value
- java
- java constructor
- java code to save excel data to mysql
- reentrantreadwritelock java
- how to ask user for his location in android
- java string to character stream
- spigot get player from UUID
- how to create a thread local variable in java
- spring iterate
- how to make an object move with arrow keys in java