This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to initialize array bidimensional ?

 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to initialize array bidimensional ?
Example:



I initialize in construct with value 0.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luigi,

[] Are the dimensions?
The that is within, are the size ?
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. And don't forget that the indexes start at 0.
 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 441
IntelliJ IDE Scala Windows
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic