关于哈希表运行的一点问题(java)
请问这里的报错究竟是什么原因造成的呢
就是在定义了Hashmap以后 用put添加元素那里会报错 为什么会这样
import java.util.HashMap;
class Solution {
HashMap<Character,Integer> symbola=new HashMap<Character,Integer>();
symbola.put('I',1);//从这里开始这七行有报错 error:<identifier> expected
symbola.put('V',5);//error:<identifier> expected
symbola.put('X',10);//error:<identifier> expected
symbola.put('L',50);//error:<identifier> expected
symbola.put('C',100);//error:<identifier> expected
symbola.put('D',500);//error:<identifier> expected
symbola.put('M',1000);//error:<identifier> expected
public int romanToInt(String s) {
int n=s.length();
int number=0;
number+=symbol.get(s.charAt(n));
for(int i=1;i<n;i++){
if(symbol.get(s.charAt(n-1-i))<symbol.get(s.charAt(n-i))){
number-=symbol.get(s.charAt(n-1-i));
}
else{
number+=symbol.get(s.charAt(n-1-i));
}
}
return number;
}
}