# 阿拉伯数字到罗马数字在线转换工具

## 如何进行阿拉伯数字到罗马数字转换?

1. 步骤1: 按顺序记住拉丁字母代表的数值 `["M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4, "I": 1]`.

2. 步骤2: 从左到右, 尝试减去最大的数值并重复,直到余0.

424 = 400 + 10 + 10 + 4 = CD + X + X + IV = CDXXIV

2019 = 1000 + 1000 + 10 + 9 = M + M + X + IX = MMXIX

1I21XXI
2II22XXII
3III23XXIII
4IV24XXIV
5V25XXV
6VI26XXVI
7VII27XXVII
8VIII28XXVIII
9IX29XXIX
10X30XXX
11XI31XXXI
12XII32XXXII
13XIII33XXXIII
14XIV34XXXIV
15XV35XXXV
16XVI36XXXVI
17XVII37XXXVII
18XVIII38XXXVIII
19XIX39XXXIX
20XX40XL

## 用Python进行阿拉伯数字到罗马数字转换:

```def transform_number_to_roman_numeral(number):
roman_value_list = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
roman_char_list = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
res = ''
for i in range(len(roman_value_list)):
while number >= roman_value_list[i]:
number -= roman_value_list[i]
res += roman_char_list[i]
return res

number_input = 987
roman_numeral_output = transform_number_to_roman_numeral(number_input)
print('number {0} equal to:{1}'.format(number_input, roman_numeral_output))

-------------------
number 987 equal to:CMLXXXVII```

## 用Java进行阿拉伯数字到罗马数字转换:

```public class NumberConvertManager {
public static String transform_number_to_roman_numeral(int number) {
int[] roman_value_list = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
String[] roman_char_list = new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
StringBuilder res = new StringBuilder();
for (int i = 0; i < roman_value_list.length; i += 1) {
while (number >= roman_value_list[i]){
number -= roman_value_list[i];
res.append(roman_char_list[i]);
}
}
return res.toString();
}

public static void main(String[] args) {
int number_input = 987;
String roman_numeral_output = transform_number_to_roman_numeral(number_input);
System.out.println("number " + number_input + " equal to:" + roman_numeral_output);
}
}

-------------------
number 987 equal to:CMLXXXVII
```