Iterator<Integer> it=res.iterator();
Integer ans=it.next(); //此处出错
if(res.isEmpty()){
return 0;
}else {
while(it.hasNext()){
int tmp=it.next();
if(tmp>ans);
ans=tmp;
}
}
```res为hashSet容器,该部分代码作用是使用迭代器遍历该容器找出最大值。
错误原因为多了一个迭代器。
ans其实只是用来接收最大值的,不能把它设置为迭代器。
int ans=0;即可
java.util.NoSuchElementException其中一种的错误
最新推荐文章于 2025-04-12 22:31:41 发布