1. Member
Join Date
May 2012
Posts
4
Rep Power
0

## Roman Numerals help

I have to convert Roman Numerals to a Decimal Number, I got how to do it, but don't know to restrict somethings,

There is a rule that one symbol cannot repeat more than three times at once, so XIIII should not work, instead it should be XIV, but I do not know how to do this.

I put an if statement within the for loop in class Translate, method numeral, but it does not work.

Java Code:
```import java.io.*;
import java.util.*;

public class RomanNumeral
{
public static void main (String[] args) throws IOException
{

for (;;)
{
System.out.println();
System.out.println("Enter roman numeral numbers:");

Translate arabNumeral = new Translate(romanNumeral);

String finalOut = arabNumeral.getNumeral();

System.out.println("The conversion is:");
System.out.println(finalOut);
}

}
}

class Translate
{
private String word, roman, result;
private int length, addition = 0;

Translate(String roman)
{
this.roman = roman;
numeral();
}

public void numeral()
{
Scanner conversion = new Scanner(roman);
StringBuffer combine = new StringBuffer ("");

while (conversion.hasNext())
{
word = conversion.next();
length = word.length();

for (int i = 0; i < length-1;i++)
{
if (word.charAt(i) == 'I' && (word.charAt(i+1) == 'V' || word.charAt(i+1) == 'X' || word.charAt(i+1) == 'L' || word.charAt(i+1) == 'C' || word.charAt(i+1) == 'D' || word.charAt(i+1) == 'M'))
{
}
else if (word.charAt(i) == 'I' && word.charAt(i+1) == 'I')
{
}
else if (word.charAt(i) == 'V' && (word.charAt(i+1) == 'X' || word.charAt(i+1) == 'L' || word.charAt(i+1) == 'C' || word.charAt(i+1) == 'D' || word.charAt(i+1) == 'M'))
{
}
else if (word.charAt(i) == 'V' && (word.charAt(i+1) == 'I' || word.charAt(i+1) == 'V'))
{
}
else if (word.charAt(i) == 'X' && (word.charAt(i+1) == 'L' || word.charAt(i+1) == 'C' || word.charAt(i+1) == 'D' || word.charAt(i+1) == 'M'))
{
}
else if (word.charAt(i) == 'X' && (word.charAt(i+1) == 'I' || word.charAt(i+1) == 'V' || word.charAt(i+1) == 'X'))
{
}
else if (word.charAt(i) == 'L' && (word.charAt(i+1) == 'C' || word.charAt(i+1) == 'D' || word.charAt(i+1) == 'M'))
{
}
else if (word.charAt(i) == 'L' && (word.charAt(i+1) == 'I' || word.charAt(i+1) == 'V' || word.charAt(i+1) == 'X' || word.charAt(i+1) == 'L'))
{
}
else if (word.charAt(i) == 'C' && (word.charAt(i+1) == 'D' || word.charAt(i+1) == 'M'))
{
}
else if (word.charAt(i) == 'C' && (word.charAt(i+1) == 'I' || word.charAt(i+1) == 'V' || word.charAt(i+1) == 'X' || word.charAt(i+1) == 'L' || word.charAt(i+1) == 'C'))
{
}
else if (word.charAt(i) == 'D' && (word.charAt(i+1) == 'M'))
{
}
else if (word.charAt(i) == 'D' && (word.charAt(i+1) == 'I' || word.charAt(i+1) == 'V' || word.charAt(i+1) == 'X' || word.charAt(i+1) == 'L' || word.charAt(i+1) == 'C' || word.charAt(i+1) == 'D'))
{
}
else if (word.charAt(i) == 'M' && (word.charAt(i+1) == 'I' || word.charAt(i+1) == 'V' || word.charAt(i+1) == 'X' || word.charAt(i+1) == 'L' || word.charAt(i+1) == 'C' || word.charAt(i+1) == 'D' || word.charAt(i+1) == 'M'))
{
}
}
if (word.charAt(length-1) == 'I')
{
}
else if (word.charAt(length-1) == 'V')
{
}
else if (word.charAt(length-1) == 'X')
{
}
else if (word.charAt(length-1) == 'L')
{
}
else if (word.charAt(length-1) == 'C')
{
}
else if (word.charAt(length-1) == 'D')
{
}
else if (word.charAt(length-1) == 'M')
{
}

combine.append(' ');

}
result = combine.toString ();
}

public String getNumeral()
{
return result;
}
}```

2. Member
Join Date
May 2012
Posts
3
Rep Power
0

3. Member
Join Date
May 2012
Posts
4
Rep Power
0

## Re: Roman Numerals help

Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•