| Author |
How to initialize array bidimensional ?
|
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
How to initialize array bidimensional ?
Example:
I initialize in construct with value 0.
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
You probably don't want the (int start[][]) in your constructor. Or if you do, at least give it a different name to your private field.
When you make a new array, you need to specify its dimensions, as inYou will find it's already full of zeros, because 0 is the default for an int.
If you wanted to put other numbers in, you could use Arrays.fill(). But you would have to loop over the arrays because in Java, there's no such thing as multi-dimensional arrays, only arrays of arrays.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Hello Luigi!
thanks by response!
See:
In that case, the array has three dimensions ? Or is, can save three int numbers ?
Thanks! (:
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
It means it has 2 dimensions, the first of which consists of 3 int[] arrays, each containing 3 ints.
You should check out a good beginners' book like Head First Java.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Luigi,
[] Are the dimensions?
The that is within, are the size ?
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
|
Yes. And don't forget that the indexes start at 0.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Very good!
More, and now, how to save numbers within of array ?
By example:
I save one number int in dimension TWO.
How ?
|
 |
Luigi Plinge
Ranch Hand
Joined: Jan 06, 2011
Posts: 441
|
|
|
http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
|
 |
 |
|
|
subject: How to initialize array bidimensional ?
|
|
|