import java.util.*;public class Test9 {
private static final Integer one = new Integer(1);
//private static final int one = 1;
public static void main(String[] args) {
Map m = new HashMap();
for(int i = 0; i < args.length; i++) {
Integer freq = (Integer)m.get(args[i]);
//int freq = (Integer)m.get(args[i]) == null ? 0 : (Integer)m.get(args[i]);
m.put(args[i],freq == null ? one : new Integer(freq.intValue() + 1)));
//m.put(args[i],freq == 0 ? one : freq + 1);
}
System.out.println(m.size() + "没有探测到输入任何内容");
System.out.println(m);
}
}
请问private static final Integer one = new Integer(1);这句话写main()里面为什么报错呢?谢谢

解决方案 »

  1.   

    多了个括号
    改为
    m.put(args[i],freq == null ? one : new Integer(freq.intValue() + 1));
      

  2.   

    谢谢,多了一个。
    请问private static final Integer one = new Integer(1);这句话写main()里面为什么报错呢?谢谢
      

  3.   

    这两行的错,freq 只能出现一次  而且你这里出现两次 当然要报错了
    Integer freq = (Integer)m.get(args[i]); 
    nt freq = (Integer)m.get(args[i]) == null ? 0 : (Integer)m.get(args[i]);
    把其中一个换成其他名字.
    不能重名. 
      

  4.   

    private变量可能定义在函数中吗?我印象中似乎没有
      

  5.   

    main中不能使用private、static修饰符,只能用final
      

  6.   

    方法中的字段不能定义为static,也不能用public,private,protected等修饰符来修饰
    只能为默认或final