OutOfBounds error

0

Well, I asked you to help me with this mistake! This is part of the code of a game, the idea and print anything like this

M M M 123456789012345678901          1 2 The positions of the M will vary with each move,

Thank you!

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 19
    at java.lang.AbstractStringBuilder.deleteCharAt(Unknown Source)
    at java.lang.StringBuilder.deleteCharAt(Unknown Source)
    at JogarBolhao3.imprimeCaminho(JogarBolhao3.java:128)
    at JogarBolhao3.jogaJogoBolhao3(JogarBolhao3.java:32)
    at WatchTheBolhao3.main(WatchTheBolhao3.java:40)

In this dim error and 21

public static void imprimeCaminho(int iniMaus [], int dim, int crateras []){


// Imprimir as posicoes dos Maus no Caminho     
StringBuilder caminhoPosicoes = new StringBuilder();
for( int i = 0; i < iniMaus.length; i++){

    for( int j = 1; j < dim; j++){
        if( iniMaus [i] == j){
            caminhoPosicoes.deleteCharAt(j); //ERRO APARECE AQUI LINHA 128
            caminhoPosicoes.append("M");
        }
    }
}

// Imprimir o Caminho

StringBuilder caminho = new StringBuilder();
for(int i = 0; i <= dim; i++){
caminho.append(i);
    if( i % 10 == 0){
    caminho.deleteCharAt(i);
    caminho.append("0");
    }
    for(int r = 0; r <= crateras.length; r++){
        if(crateras [r] == i){
        caminho.deleteCharAt(i);
    }
    }
    }


// Imprimir as Dezenas no Caminho
StringBuilder caminhoDezenas = new StringBuilder();
for(int i = 0; i <= dim; i++){
    if( i % 10 == 0){
        int d = (i / 10);
        caminhoDezenas.append(d);
    }
        for(int r = 0; r <= crateras.length; r++){
            if(crateras [r] == i){
            caminho.deleteCharAt(i);
    }
    }
}

System.out.println(caminhoPosicoes.toString());
System.out.println(caminho.toString());
System.out.println(caminhoDezenas.toString());
}
    
asked by anonymous 02.12.2016 / 11:48

0 answers