各位请帮忙_急!在线等!-超简单的问题package shiYan;

BeyondImagine 2006-11-21 02:53:21
为什么是一样的代码在Jbuilder2006中运行没问题,到Eclips中就报错
请帮我看哪错了
package shiYan;
import java.util.*;
public class Map {
public Map(){


}

public static void main(String[] args) {
int i;
int[]a={1,2,3,4,5};
HashMap map=new HashMap;
for( i=0;i<a.length;i++)

{

map.put(new Integer(a[]), new Integer(a[i] * a[i]));

System.out.println("map["+i+"]="+map.get(a[i]));
}

}

}
...全文
122 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jy02209334 2006-11-21
  • 打赏
  • 举报
回复
建议用范型.
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int[] a = {1,2,3,4,5};
for(int i=0;i<a.length;i++)
{
map.put(a[i], a[i]*a[i]);
System.out.println("map["+i+"]="+map.get(a[i]));
}
BeyondImagine 2006-11-21
  • 打赏
  • 举报
回复
package shiYan;
import java.util.*;
public class Map {
public Map(){


}

public static void main(String[] args) {
int i;
int[]a={1,2,3,4,5};
改动前HashMap map=new HashMap;

改动后:HashMap<Integer, Integer> map=new HashMap<Integer, Integer>();
for( i=0;i<a.length;i++)

{

map.put(new Integer(a[i]), new Integer(a[i] * a[i]));


System.out.println("map["+i+"]="+map.get(a[i]));


//System.out.println("map["+i+"]="+map.get(new Integer(a[i])));


}

}

}
为什么这样改就全没问题呢?请高手解释下
小弟谢了
BeyondImagine 2006-11-21
  • 打赏
  • 举报
回复
你能调试一下吗
拜托啊jackxing
BeyondImagine 2006-11-21
  • 打赏
  • 举报
回复
map.put(new Integer(a[i]), new Integer(a[i] * a[i]));

上面这句代码还是有错啊

这句好了HashMap map=new HashMap();
jy02209334 2006-11-21
  • 打赏
  • 举报
回复
HashMap map=new HashMap;->HashMap map = new HashMap();
new Integer(a[]) ?? a[i]
jackxing 2006-11-21
  • 打赏
  • 举报
回复
1)HashMap map=new HashMap;
-> HashMap map=new HashMap();

2)map.put(new Integer(a[]), new Integer(a[i] * a[i]));
-> map.put(new Integer(a[i]), new Integer(a[i] * a[i]));

3)System.out.println("map["+i+"]="+map.get(a[i]));
-> System.out.println("map["+i+"]="+map.get(new Integer(a[i])));

BeyondImagine 2006-11-21
  • 打赏
  • 举报
回复
错误是:

(1)无法解析HashMap
(2)new上有语法错误
(3)put(object,object)属于原始类型HashMap


BeyondImagine 2006-11-21
  • 打赏
  • 举报
回复
(1)无法解析HashMap
(2)new上有语法错误
(3)put(object,object)属于原始类型HashMap
zhuixun5506 2006-11-21
  • 打赏
  • 举报
回复
什么错误,给出错误信息好不?

不过,你就不能想个好点的类名吗?Map, 容易与jdk中的冲突
fang830422 2006-11-21
  • 打赏
  • 举报
回复
把报错的内容发上来!

62,630

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧