我正在为我的班级写一个罗马数字程序.我正在使用switch语句将字符串转换为整数.但是,当我运行它时,我得到一个不兼容的类型错误.我正在运行java 7,所以这不是问题.这是我的代码:
public static void main()
{
// Declare local variables
Scanner input = new Scanner(System.in);
String rNum;
int i;
int[] rArray;
// Display program purpose
System.out.println("This Program Converts Roman numerals to decimals");
System.out.println("The Roman numerals are I (1), V (5), X (10), L (50), C (100), D (500) and M (1000).");
System.out.print("Enter your roman numeral: ");
rNum = input.next().toUpperCase();
rArray = new int[rNum.length()];
for(i = 0; i < rNum.length(); i++){
switch(rNum.charAt(i)){
case "I": rArray[i] = 1;
break;
}
}
Run Code Online (Sandbox Code Playgroud)