分配时&&做/意味着什么? JAVA

时间:2022-12-19 16:57:18

I know that && can be used to check if the both conditions are satisfied when it is used in a conditional statement but how do you explain
full[i][j] = open[i][j] && full[i - 1][j]; ??
In case we are reading this piece of code how do we explain this?

Notice that full and open are two 2D Boolean arrays

我知道&&可以用来检查条件语句中是否满足这两个条件,但是如何解释完整[i] [j] = open [i] [j] && full [i - 1] [J]; ??如果我们正在阅读这段代码,我们如何解释这个?请注意,full和open是两个2D布尔数组

//i = column j = row
for (int i = 1; i < N; i++) {
            for (int j = 0; j < N; j++) {
                full[i][j] = open[i][j] && full[i - 1][j];
               //^^ what happens here?
}

3 个解决方案

#1


1  

 full[i][j] = open[i][j] && full[i - 1][j];

Means that that [i][j] && full[i - 1][j] will resolves to a boolean and assigning it as a boolean element in another array.

意味着[i] [j] && full [i - 1] [j]将解析为布尔值并将其指定为另一个数组中的布尔元素。

#2


0  

I think (Not 100% sure) that it is assigning values, When we are using primitive data types we can use a single & to do bit wise anding, While we are doing the same for boolean values,

我认为(不是100%肯定)它正在分配值,当我们使用原始数据类型时,我们可以使用单个&做有点明智的方法,而我们对布尔值做同样的事情,

full[i][j] = open[i][j] && full[i - 1][j]; 

Means we are assigning anded boolean value of open[i][j] and full[i-1][j] to full[i][j].

意味着我们将open [i] [j]和full [i-1] [j]的anded布尔值赋值给full [i] [j]。

#3


0  

By default all the values of full array are false.

默认情况下,full数组的所有值都为false。

Initially for i=1 and j=0. Value of full[0][0] will false. So whatever open[][] value is , full[1][0] will have false value.

最初为i = 1且j = 0。 full [0] [0]的值将为false。因此无论open [] []值是什么,full [1] [0]都将具有false值。

Correct me if I understand your question worong.

如果我理解你的问题,请纠正我。

#1


1  

 full[i][j] = open[i][j] && full[i - 1][j];

Means that that [i][j] && full[i - 1][j] will resolves to a boolean and assigning it as a boolean element in another array.

意味着[i] [j] && full [i - 1] [j]将解析为布尔值并将其指定为另一个数组中的布尔元素。

#2


0  

I think (Not 100% sure) that it is assigning values, When we are using primitive data types we can use a single & to do bit wise anding, While we are doing the same for boolean values,

我认为(不是100%肯定)它正在分配值,当我们使用原始数据类型时,我们可以使用单个&做有点明智的方法,而我们对布尔值做同样的事情,

full[i][j] = open[i][j] && full[i - 1][j]; 

Means we are assigning anded boolean value of open[i][j] and full[i-1][j] to full[i][j].

意味着我们将open [i] [j]和full [i-1] [j]的anded布尔值赋值给full [i] [j]。

#3


0  

By default all the values of full array are false.

默认情况下,full数组的所有值都为false。

Initially for i=1 and j=0. Value of full[0][0] will false. So whatever open[][] value is , full[1][0] will have false value.

最初为i = 1且j = 0。 full [0] [0]的值将为false。因此无论open [] []值是什么,full [1] [0]都将具有false值。

Correct me if I understand your question worong.

如果我理解你的问题,请纠正我。