Question: I am trying to convert roman numerals into regular numbers using java. I am using intellij for my ide. Please proof my code so that

I am trying to convert roman numerals into regular numbers using java. I am using intellij for my ide. Please proof my code so that it may run.

public class RomanNumeralsToNumbers {

public static void main(string[] args) {

string str = "DCCVII"; int len = str.lenth(); str = str + " "; int result = 0; for (int i = 0; i < len; i++) { //for loop char ch = str.charAt(i); char next_char = str.char.At(i + 1); //next roman numeral if (ch == 'M') { result += 1000; } else if (ch == 'C') { if (next_char == 'M') { result += 900; i++; } else if (next_char == 'D') { //next roman numeral result += 400; i++; } else { result += 100; } else if (ch == 'X') { if (next_char == 'C') { result += 90; //result of X and C i++; } else if (next_char == 'L') { result += 40; i++; } else { result += 10; } } else if (ch == 'L') { result += 50; } else if (ch == 'I') { if (next_char == 'X') { result += 9; i++; } else if (next_char == 'V') { result += 4; i++; } else { result++; } } else { result += 5; } System.out.println(" Roman Number: " + str); System.out.println("Equivalent integer: " + result + " "); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!