-2

I am fairly new at java programming, and i haven't come up with this error before. I will accept any and all advices,so if you know anything about this please help.

package proba;

public class Kraljica2 {

    public static void main(String[] args) {
        int x = 6;
        int y = 4;
        int i;
        int j;
        int m;
        int t;
        int h;
        int g=x+y;


        int[][] a = new int [7][7];{

        if(x==y) {
            for(t=0;t<8;t++){
                for(m=0;m<8;m++){
                    if(t==m){
                        a[t][m]=1;
                            }
                                }

                            }
                 }  

        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                h=i+j;
                if(i==x||j==y||g==h){
                    a[i][j]= 1;
                }

            }
        }
        for(i=0;i<8;i++){
            for(j=0;j<8;j++){
                System.out.print(a[i][j]);

            }
            System.out.println();
    }






    }
}}

I am doing the queens movement in chess,(showing where she can go from coordinates x and y). If anything seems noobish, it is like that because I am a noob with java. :D

Bacteria
  • 8,406
  • 10
  • 50
  • 67

1 Answers1

1

You have slots 0 - 6 (size 7) an you try to access on slot 7

Learn something about arrays: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

pL4Gu33
  • 2,045
  • 16
  • 38