Given a Roman numeral, the task is to find the corresponding decimal value.
Note: Roman numerals are represented by seven different symbols: I, V, X, L, C, D, and M.
- Loop through each character in the string containing the Roman numerals.
- Compare the value of the current roman symbol with the value of the roman symbol to its right. If the current value is greater than or equal to the value of the symbol to the right, add the current symbol’s value to the total. If the current value is smaller than the value of the symbol to the right, subtract the current symbol’s value from the total.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.