【发布时间】:2021-03-07 10:52:52
【问题描述】:
我正在尝试获取两个集合的并集,但由于某种原因,我的代码没有错误,但我获取并集的方法跳过了一些代码
public Set union(Set s){
Set union = new Set(count+s.count);
for(int x=0;x<count;x++)
union.set[x] = set[x];
for(int y=count;y<s.count;y++){
union.set[y] = s.set[y];
}
return union;
}
程序可以运行,但问题是在第一个循环之后它会跳过方法中的其余代码。
这是我可能与问题相关的其余代码
public class Set implements InterfaceSet{
private int set[];
private int count;
public Set(){
set = new int[max];
count = 0;
}
public Set(int size){
set = new int[size];
count = size;
}
private int found;
public void add(int e){
found = 0;
if(count<10){
for(int x: set){
if(x==e){
found=1;
break;
}
}
if(found==0){
set[count] = e;
count++;
}
}
}
public void display( ){
for(int x=0;x < count; x++){
System.out.println(set[x]);
}
}
【问题讨论】:
标签: java loops for-loop methods