我制作了一个哈希图,将罗马数字存储为键,将十进制数字存储为值。错误显示“不兼容的类型 - 找到 java.lang.Object 但预期为 int”。当我写“conversions.get(numOne.charAt(x));”时,我只是想获取罗马数字的值 我在这里做错了什么?
import java.util.Scanner;
import java.util.HashMap;
public class test
{
static Scanner sc = new Scanner(System.in);
static HashMap conversions = new HashMap();
public static void main(String args[]){
conversions.put('I',1);
conversions.put('V',5);
conversions.put('X',10);
conversions.put('L',50);
conversions.put('C',100);
conversions.put('D',500);
conversions.put('M',1000);
String numOne = "XIX";
for(int x = 0; x <= numOne.length()-2; x++){
int temp1 = conversions.get(numOne.charAt(x));
int temp2 = conversions.get(numOne.charAt(x+1));
}
}
}