显示的问题是这样的
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Lab1.main(lab1.java:4)
这是我的代码
import java.util.Scanner;
public class Lab1{
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
int size1 = a.nextInt();
int [] answer1 = new int[size1];
for(int i = 0 ; i < size1; i++){
answer1[i] = a.nextInt();
}
Scanner b = new Scanner(System.in);
int size2 = b.nextInt();
int [] answer2 = new int[size2];
for(int j = 0 ; j < size2; j++){
answer2[j] = b.nextInt();
}
Set set1 = new Set();
Set set2 = new Set();
for(int i = 0 ; i < answer1.length;i++)
set1.add(answer1[i]);
for(int j = 0 ; j < answer2.length;j++)
set2.add(answer2[j]);
if(set1.compare(set2))
System.out.println("The sets are equal!");
else
System.out.println("The sets are different!");
}
}
class Set {
private int[] data;
private int size;
public Set() {
data = new int[20];
size = 0;
}
public void add(int value) {
int[] copy;
if (!in(value)) {
if (size >= data.length) {
// Resize the array
copy = new int[data.length * 2];
System.arraycopy(data, 0, copy, 0, data.length);
data = copy;
}
data[size] = value;
size++;
}
}
public boolean in(int value) {
for (int i = 0; i < size; i++) {
if (data[i] == value)
return true;
}
return false;
}
public Set intersection(Set other) {
Set result = new Set();
for (int i = 0; i < size; i++) {
if (other.in(data[i]))
result.add(data[i]);
}
return result;
}
public Set union(Set other) {
Set result = (Set)other.clone();
for (int i = 0; i < size; i++) {
result.add(data[i]);
}
return result;
}
public Object clone() {
Set result = new Set();
for (int i = 0; i < size; i++) {
result.add(data[i]);
}
return result;
}
public String toString() {
String result = "{";
for (int i = 0; i < size; i++) {
result += " " + data[i];
// Add a comma after all but the last item
if (i < size - 1)
result += ",";
}
result += " }";
return result;
}
public boolean compare( Set other){
boolean check = true;//in(data[i]) this.in(data[i])
for(int i = 0 ; i < size; i++){
check = other.in(this.data[i]);
if(!check)
return check;
}
return check;
}
}