此数组中的搜索号码是代码:保持在java中
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正如你所看到的,还有另外12阵列3.我怎样才能让它继续,并寻找第二个12?我不希望它终止在第一个12. 谢谢你。
啊。谢啦!! :D – iG0tB0lts 2012-07-17 14:03:53
欢迎您:) – 2012-07-17 14:04:25
如果您查看代码,该更改将与打印语句有关 – 2012-07-17 14:05:41