简体   繁体   English

二元运算符'&&'的错误操作数类型

[英]bad operand types for binary operator '&&'

Not sure what is wrong here.不知道这里有什么问题。 This line "if (ocean[row][col]==null && ocean2[row][col] = null)".这一行“if (ocean[row][col]==null && ocean2[row][col] = null)”。 I tried ((ocean[row][col])==null && (ocean2[row][col]) = null).我试过 ((ocean[row][col])==null && (ocean2[row][col]) = null)。 Still it's wrong.还是错了。 Can anyone help me?谁能帮我?

public static void deployCompShips(String[][] ocean) {
            Random rand = new Random();
            System.out.println("Computer is deploying ships");
            while (compShips < 5) {
                int col = rand.nextInt(10);
                int row = rand.nextInt(10);
    
                if (ocean[row][col]==null && ocean2[row][col] = null) {
                    System.out.println((compShips+1)+". ship DEPLOYED");
                    ocean2[row][col] = "@";
                    compShips++;
                }
            }
        }

You can't use assignment operator to compare two values.您不能使用赋值运算符来比较两个值。

                                              
if (ocean[row][col]==null && ocean2[row][col] = null) 
                                              ^
                                              |
                                      using assignment operator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM