So basicly i am trying to create a 2 dimensional array for my snake game but i am haveing some trouble:

public static Tile gameField[][];
gameField = new Tile[FIELD_HEIGHT][FIELD_WIDTH];
for(int i=0;i<FIELD_HEIGHT;i++){
    for(int j=0;j<FIELD_WIDTH;j++){
        gameField[i][j] = new Tile();
    }
}
gameField[1][1].snake = false;
gameField[1][2].snake = true;
System.out.println(gameField[1][1].snake+"_"+gameField[1][2].snake);

//Prints: true_true
public class Tile {
    public static boolean snake;
    public static int id;
}

I´d appreciate if someone could help me with this problem.

Agree with James, all tiles will share the same snake/id. I dont understand what you are trying to achieve with that.

Hello, this isnt about a 2d array but about 1d array, hope its not wrong to post my question in here.

i have these grades for the tests;

int grade3subject[]=                  {1,3,5,1,2,3,5};
int grade4subject[]={3,5,3,2,3,4,2};

i want to acces both arrays and make a sum for each "student" from both arrays...
1+3, 3+5... etc

for (int i = 0; i < grade3subject.length; i++) {



for (int j = 0; j < grade4subject.length; j++) {
int sum; //summ of grades


sum = grade3subject+grade4subject[j];

aint working..
i know how to do it from a 2d array.... unfortunately i need 2 seperate arrays, please help.

Greetz

Edited 3 Years Ago by happygeek: fixed formatting

Hello, this isnt about a 2d array but about 1d array, hope its not wrong to post my question in here.

i have these grades for the tests;

int grade3subject[]= {1,3,5,1,2,3,5};
int grade4subject[]={3,5,3,2,3,4,2};


i want to acces both arrays and make a sum for each "student" from both arrays...
1+3, 3+5... etc


for (int i = 0; i < grade3subject.length; i++) {


for (int j = 0; j < grade4subject.length; j++) {
int sum; //summ of grades

sum = grade3subject+grade4subject[j];


aint working..
i know how to do it from a 2d array.... unfortunately i need 2 seperate arrays, please help.

Greetz

int[] grade3subject= {1,3,5,1,2,3,5};	
int[] grade4subject={3,5,3,2,3,4,2};

for (int i = 0; i < grade3subject.length; i++) {
    int sum; //summ of grades

    sum = grade3subject[i]+grade4subject[i];
}

one loop to much

Edited 6 Years Ago by forsan200: n/a

This article has been dead for over six months. Start a new discussion instead.