这是代码:
public class test2 {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
int[][] arrayOfInts = {
{ 32, 87, 3, 589 },
{ 622, 1076, 2000, 8 },
{ 12, 127, 77, 955 },
{12, 3}
};
int searchfor = 12;
int i;
int j = 0;
boolean foundIt = false;
search:
for (i = 0; i < arrayOfInts.length; i++) {
for (j = 0; j < arrayOfInts[i].length;
j++) {
if (arrayOfInts[i][j] == searchfor) {
foundIt = true;
break search;
}
}
}
if (foundIt) {
System.out.println("Found " + searchfor +
" at " + i + ", " + j);
} else {
System.out.println(searchfor +
" not in the array");
}
}
}
此代码在前 12 处停止。如您所见,数组 3 中还有另一个 12。我怎样才能让它继续下去,并搜索第二个 12?我不希望它在前 12 点终止。谢谢。