Why that mistake

Asked

Viewed 46 times

0

Can someone please explain to me this mistake?

<%

    String[][] mesa = new String[30][30];

    out.println("");
    for(int i=30; i>=0; i--)
    {
        for(int n=0; n<((302)+1); n++)
        {
            out.print("-");
        }
        out.println("<br>");
        for(int j=0; j<30; j++)
        {
            mesa[i][j]=" ";
            out.print("|" + mesa[i][j]);
        }
        out.print("|<br>");
    }

    for(int n=0; n<((302)+1); n++)
    {
        out.print("-");
    }
    out.println("<br>");

%>

Esse é o erro que aparece no navegador

1 answer

3


You have declared the table variable with 30 rows and columns, so the access range for this variable is 0 to 29, however in the "for(int i=30; i>=0; i--)" loop, you access the variable at position 30 causing the exception, try to change the initialization from i to 29.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.