How to check if there is a number in an array?

0

I have this arrangement. The letters move only if the next position is a zero and my question is how can I check if the next position is a zero?

// Part of my code

                System.out.println("¿A que numero desea moverla?");
                int posicioni = menu.nextInt();
                System.out.println("¿A que letra desea moverla?");
                int posicionj = menu.nextInt();

                b1 = posicioni;//Se le asigna a b1 la nueva posicion
                b2 = posicionj;//Se le asigna a b2 la nueva posicion


                for (i = 0; i < matriza.length; i++) {
                    for (j = 0; j < matriza.length; j++) {

                        System.out.print(matriza[i][j] + " ");
                        matriza[4][6] = "0";
                        matriza[b1][b2] = "r";

                    }

                    System.out.println("");
                }
                Mov++;//Contador para los movimientos
                }
    
asked by TGAB99 04.11.2018 в 21:40
source

2 answers

0

You can do it with the Character.IsDigit (char) method; That method returns true or false depending on whether the char passed to you by parameter is a number or not.

On this page you have more information about this method: link

    
answered by 04.11.2018 в 22:32
0

You can use a method that controls whether the entered String is numeric or not

 public boolean isNumeric(String cadena) {

    boolean resultado;

    try {// se controla una posible excepcion
        Integer.parseInt(cadena);// si se logra guardar correctamente es un numero
        resultado = true;
    } catch (NumberFormatException excepcion) {//si no se logra guardar correctamente ocurre lo siguente:
        resultado = false;
    }

    return resultado;
}
    
answered by 05.11.2018 в 05:14