Why does it mark me error String index out of range: -1?

-1
String Nombre="armando";




    for (int i = 6; i <Nombre.length(); i--) {
        for (int j = 0; j < Nombre.length(); j++) {

        char n =Nombre.charAt(i);//Se supone que en esta linea esta el error

        char matriz[][] = new char [n][n];

            if (j == i) {
                matriz[i][j] =n ;



            }

                    System.out.print(matriz[i][j] +"  " );
        }
                System.out.println("");
        }
    }
    }

This is the code where you mark error

    
asked by TGAB99 26.10.2018 в 23:25
source

1 answer

2

Change for (int i = 6; i <Nombre.length(); i--) by for (int i = Nombre.length() - 1; i > -1; i--)

Remember that the indexes start from zero to size -1 and that when the cycle is subtracting you must ensure that you do not fall into negatives i> -1 (zero would be the first character)

    
answered by 26.10.2018 / 23:38
source