1 回答
TA贡献1770条经验 获得超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;
}
另一种更快的方法是在更改数组的一个布尔值时尝试对数组进行排序,然后仅检查数组中的第一个或最后一个布尔值
添加回答
举报