Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Given an integer, convert it to a Roman number.
The input value can be between 1 and 3999.
Is a conversion rule.
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
I |
II |
III |
IV |
V |
VI |
VII |
VIII |
IX |
|
|
|
|
|
|
|
|
|
10 |
20 |
30 |
40 |
50 |
60 |
70 |
80 |
90 |
X |
XX |
XXX |
XL |
L |
LX |
LXX |
LXXX |
XC |
|
|
|
|
|
|
|
|
|
100 |
200 |
300 |
400 |
500 |
600 |
700 |
800 |
900 |
C |
CC |
CCC |
CD |
D |
DC |
DCC |
DCCC |
CM
|
The following program uses the example code to write the above table using if else. Of course, this course schedule is also regular. For example, the course starts with 1-3 and repeats. The last character is intercepted from 4-5, and the last character is added from 6 to 8.
Public static String intToRoman (int num) {StringBuffer buf = new StringBuffer (); int dddd = num/1000; int ddd = num % 1000/100; int dd = num % 1000%; int d = num % 1000% 100% 10; for (int I = 0; I
See this http://www.mathsisfun.com/roman-numerals.html for conversion rules for integers and Roman numerals.