In my program that turns roman numerals into arabic numbers I have run across the error
incompatible types: java.lang.String cannot be converted into int
Here is my code
if ( Character.isDigit(TextIO.peek()) ) {
int arabic = TextIO.getlnInt();
try {
RomanNumerals N = new RomanNumerals(arabic);
TextIO.putln(N.toInt() + " = " + N.toString());
}
catch (NumberFormatException e) {
System.out.println("Invalid input.");
System.out.println(e.getMessage());
}
}
else {
String roman = TextIO.getln();
try {
RomanNumerals N = new RomanNumerals(roman);
System.out.println(N.toString() + " = " + N.toInt());
}
catch (NumberFormatException e) {
System.out.println("Invalid input.");
System.out.println(e.getMessage());
}
}
I am using BlueJ and the error is being highlighted over "(roman)"
RomanNumeralsmust expect anint, and you're giving it aString. You need to convert it into anint.