error with incompatible can not convert to bolean and in operator &&

0

package mineralogues;

public class MatrizMinas {

    //atributos
    private int valores[][];

    //constructor

    public MatrizMinas(){
        valores = new int [10][10];
        limpiarMinas();
    }
    //limpiar la pantalla
    public void limpiarMinas(){

        for (int m = 0; m < 10; m++){
            for (int n = 0; n < 10; n++){
                valores[m][n] = 0;

            }
        }
    }

    //insertar aleatoriamente las minas 
    public void ponerMinas(){
        limpiarMinas();

        int m;
        int n;

        for (int i = 0; i < 10; i++){
            do{
                m = (int) (Math.random() * 10) ;
                n = (int) (Math.random() * 10) ;
            ***}while (valores[m][n] ! = 0);***
            valores [m][n] = 9;
        }


    }

    //devolver el valor de la casilla 
    public int getMina (int m, int n){
        return valores [m][n];
    }

    //calcular contorno de la mina
    public void calcularContornos(){
        for (int m = 0; m < 10; m++){
            for (int n = 0; n < 10; n++){
                if (valores[m][n] = 9){
                    for (int m2 = m - 1; m2 <= m + 1; m2++){
                        for (int n2 = n - 1; n2 <= n + 1; n2++){
                            ***if (m2 >=0 && m2 < 10 && n2 >= 0 && n2 < 10 && valores [m][n]){***
                                valores[m2][n2]++;
                            }
                        }
                    }
                }
            }
        }
    }
}
    
asked by bryan 24.09.2018 в 05:34
source

2 answers

2

You have two syntax problems; the first of them and the one that you frame in the question:

if (m2 >=0 && m2 < 10 && n2 >= 0 && n2 < 10 && valores [m][n] ??)

The logical operators work on boolean values, in valores [m][n] you are returning an integer, you must compare it with something. The other error you have is in the do while in ponerMinas , the stop condition of the cycle while (valores[m][n] ! = 0) , the comparator != should not take spaces between them, leaving:

while (valores[m][n] != 0)
    
answered by 24.09.2018 в 06:06
0

At the end of your if you put values [m] [n] which is an integer, not a boolean, that's why it's your error.

It was stated:

private int valores [][];
valores = new int [10] [10];

Which is an array of integers, so in your code you put the following at the end of the

if (m2 >=0 
    && m2 < 10 
    && n2 >= 0 
    && n2 < 10
    && valores [m][n]){// aquí está tu error valores como explicó arriba es un entero no un booleano
    //Logica
}
    
answered by 24.09.2018 в 05:58