# Thread: Need help with 2D arrays...

1. Member
Join Date
Nov 2008
Posts
3
Rep Power
0

## Need help with 2D arrays...

Ok here is the deal....I got homework and my Java teacher is asking me to create this simple little game(no GUI just numbers and letters showing in a console) I know how to do pretty much everything but one thing.....the 2d string array game board.....he want something that look like this..
0 1 2 3 4 5 6 7 8 9 10 11
0
1
2
3
4
5
6
7
8
9
10
11
0 1 2 3 4 5 6 7 8 9 10 11
(plus a right side thats goes the same way as the left)

I can only get this...dont know how to create the bottom and right side
0 1 2 3 4 5 6 7 8 9 10 11 12 13
1
2
3
4
5
6
7
8
9
10
11
12
13

here are my codes that create the board......

public Partie (int vertical , int horizontal)
{
tableau = new String [vertical+2][horizontal+2];
for (int v = 0 ; v<tableau.length ; v++ )
{
for(int h = 0 ; h<tableau.length ; h++)
{
tableau[0][h] = "" + String.format("%1\$3d", ((h)));
}
}
for (int v = 0 ; v<tableau.length ; v++ )
{
for(int h = 0 ; h<tableau.length ; h++)
{
tableau[v][0] = "" + String.format("%1\$3d", ((v)));
}
}

}

I know there should be a tableau.length-1 ....just dont know how to use it...
Any help will be greatly appreciated ! Thanks in advance

2. Member
Join Date
Nov 2008
Posts
3
Rep Power
0
All right well....the teacher made a main for us so that de game board is a square 12 x 12 but in our constructor it must be 2 more so lets say its 14x14 so so every side of the square must be numbered from 0 to 13 and thats pretty much it ...the only thing that I cant figure out is how to reverse the arrays so it displays the bottom 0 to13 and the right side 0 to 13.

3. If you want to revers the array, start from the last element. But I'm confusing, that how to add numbers in the bottom like 0-13??? I think it should be 13-0, because the very bottom number in the left side column is 13, is it?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•