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.

You declared the variables in Tile as static!

commented: Exactly! +6

please specify what trouble you got and what you need exactly..

i think james is correct...

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

yea I didnt realise that but its all fixed now thanks ^^

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

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

Almost... declare and initialise sum outside the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.