1 回答

TA貢獻(xiàn)1770條經(jīng)驗 獲得超3個贊
只需瀏覽整個列表并檢查真假
public static void main(String[] args) {
boolean[] array = new boolean[] {false,true,true,false,true};
int index = 0;
while(!checkBooleanArray(array)) { //check
array[index] = true; //do something about it
index++; //increasing the index and then check again
} //you obviously have to change the the part of "do something" and "increasing index" to match your wishes
System.out.println(Arrays.toString(array));
}
public static boolean checkBooleanArray(boolean[] array) {
for (boolean b : array)
if (!b)
return false;
return true;
}
另一種更快的方法是在更改數(shù)組的一個布爾值時嘗試對數(shù)組進(jìn)行排序,然后僅檢查數(shù)組中的第一個或最后一個布爾值
添加回答
舉報