Given an integer, convert it to a Roman numeral.
Input is guaranteed to being within the range from 1 to 3999.
| Basic characters |
I |
V |
X |
L |
C |
D |
M |
| The corresponding Arabic numerals are expressed as |
1 |
5 |
10 |
50 |
100 |
500 |
1000 |
- The same number ligatures, the number represented is equal to the number of these numbers added, such as: ⅲ= 3;
- The small number is on the right side of the large number, and the number represented is equal to the number added to the number, such as: ⅷ= 8;ⅻ= 12;
- Small numbers, (limited to Ⅰ, X, and C) on the left side of the large number, represented by the number equal to the number of large reduction numbers obtained, such as: ⅳ= 4;ⅸ= 9;
- In normal use, the number of ligatures cannot be repeated more than three times. (Exception of four O'Clock "IIII" on the dial)
- Draw a horizontal line over a number to indicate that the number is enlarged 1000 times times.
1 Public classSolution {2 PublicString Inttoroman (intnum) {3String [] i = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};4String [] x = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};5String [] C = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};6String [] m = {"", "M", "MM", "MMM"};7 8 return(m[num/1000] + c[(num%)/100] + x[(num%)/10] + i[num% 10]). Trim ();9 }Ten}
The China bit is answer.
Integer to Roman Java solutions