我正在关注的罗马数字到整数转换器:
https://www.selftaughtjs.com/algorithm-sundays-converting-roman-numerals/
我尝试将 Javascript 函数转换为 Java:
public class RomanToDecimal {
public static void main (String[] args) {
int result = 0;
int[] decimal = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
String[] roman = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
// Test string, the number 895
String test = "DCCCXCV";
for (int i = 0; i < decimal.length; i++ ) {
while (test.indexOf(roman[i]) == 0) {
result …Run Code Online (Sandbox Code Playgroud)