mercredi 21 février 2018

Fill a 2D array with random uppercase characters

I have this constructor for building a word search game (or are those called "alphabet soups"?). Its purpose is to create a two-dimensional array and then fill it with random uppercase letters.

SopaLetras(int numFilas, int numColumnas){
    this.numFilas = numFilas;
    this.numColumnas = numColumnas;
    char letra;
    cuadricula = new char[numFilas][numColumnas];
    for (int i = 0; i > numFilas; i++){
        for (int j = 0; j < numColumnas; j++){
            letra = (char)(65+(int)(Math.random()*26));
            cuadricula[i][j] = letra;
        }
    }
}

However, whenever i initialize this cuadricula[][] and try to check for any of its spaces, it always returns an empty character. I've checked the usage of Math.random(), it is correct and that statement is able to return a random uppercase character when putting it in a System.out.println().

¿What is it that makes me unable to assign that char to that place in the array?

Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire