I am trying to use substrings to calculate what the Roman numerals equal in arabic numbers, and I keep getting an index out of range error. Or, another way I had it, it would just read the second numeral and completely ignore the first.
System.out.println("What is the number you want converted?");
Scanner scan = new Scanner(System.in);
String Roman = scan.next();
int sum = 0;
for (int x = 0; x<Roman.length(); x++)
{
if (Roman.substring(x,(x+2)).equals("XC"))
{
sum= sum+90;
}
else if (Roman.substring(x,(x+1)).equals("IX"))
{
sum= sum+9;
}
else if (Roman.substring(x).equals("X"))
{
sum= sum+10;
}
else if (Roman.substring(x,(x+2)).equals("IV "))
{
sum= sum+4;
}
else if (Roman.substring(x).equals("V"))
{
sum= sum+5;
}
else if (Roman.substring(x).equals("I"))
{
sum= sum+1;
}
else if (Roman.substring(x).equals("L"))
{
sum= sum+50;
}
else if(Roman.substring(x).equals("C"))
{
sum= sum+100;
}
}
System.out.println(sum);