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 and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Program to Convert HashMap to TreeMap in Java
- How to Convert HashMap to ArrayList in Java?
- Java Program to Convert a Decimal Number to Binary & Count the Number of 1s
- Check whether two Strings are Anagram of each other using HashMap in Java
- Java program to count the occurrence of each character in a string using Hashmap
- Java Program to Convert Octal to Decimal
- Remove an Entry using key from HashMap while Iterating over it
- Remove an Entry using value from HashMap while Iterating over it
- HashMap and TreeMap in Java
- HashMap Class Methods in Java with Examples | Set 1 (put(), get(), isEmpty() and size())
- Hashmap methods in Java with Examples | Set 2 (keySet(), values(), containsKey()..)
- Hashmap vs WeakHashMap in Java
- Internal Working of HashMap in Java
- Differences between HashMap and HashTable in Java
- Differences between TreeMap, HashMap and LinkedHashMap in Java
- Sorting a HashMap according to keys in Java
- HashMap clear() Method in Java
- HashMap containsKey() Method in Java
- HashMap clone() Method in Java
- HashMap containsValue() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.