AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
3. Our Experts are looking for yours ?.

# corejava-string-handling: Roman Numbers in java

 Write a java program to take a roman number as input and print the decimal equivalent of the same. Sample Input: IV Sample Output: 4 corejava x 353string-handling x 34 Posted On : 2016-10-11 20:34:28.0 Aarti Kumar 5900 4

 // Program to convert Roman Numerals to Numbers import java.util.*; public class RomanToDecimal { // This function returns value of a Roman symbol int value(char r) { if (r == ´I´) return 1; if (r == ´V´) return 5; if (r == ´X´) return 10; if (r == ´L´) return 50; if (r == ´C´) return 100; if (r == ´D´) return 500; if (r == ´M´) return 1000; return -1; } // Finds decimal value of a given romal numeral int romanToDecimal(String str) { // Initialize result int res = 0; for (int i=0; i= s2) { // Value of current symbol is greater // or equalto the next symbol res = res + s1; } else { res = res + s2 - s1; i++; // Value of current symbol is // less than the next symbol } } else { res = res + s1; i++; } } return res; } // Driver method public static void main(String args[]) { RomanToDecimal ob = new RomanToDecimal(); // Considering inputs given are valid String str = new Scanner(System.in).nextLine(); System.out.println("Integer form of Roman Numeral" + " is " + ob.romanToDecimal(str)); } } Posted On : 2016-10-12 23:55:49 Satisfied : 1 Yes  0 No Rishi Kumar 528188225058Reply This Thread 5