我编写了一些代码,它将在 10000 个随机数的文件中连续搜索 1000 个键,并打印出 arr 找到的键。
这是下面的代码。当我运行它但我什么也没得到。我的错误在哪里?
public class SeqSample2 {
public static void main(String[] args) {
double[] a;
double[] b;
a = new double[10000];
b = new double[1000];
for (int i = 0; i < 1000; i++) {
a[i] = (int) ((Math.random() * 10000));
}
for (int j = 0; j < 1000; j++) {
b[j] = (int) ((Math.random() * 1000));
}
int lim = a.length - b.length;
int i = 0;
int j = 0;
boolean found = false;
for (i = 0; i < lim; i++) {
if (b[0] == a[i]) {
found = true;
for (j = 0; j < b.length; j++) {
if (b[j] != a[i + j]) {
found = false;
break;
}
}
if (found) {
System.out.println(b[i]);
} else {
System.out.println("Not found");
}
}
}
}
}