This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Loading 2-dimensional array with values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loading 2-dimensional array with values" Watch "Loading 2-dimensional array with values" New topic
Author

Loading 2-dimensional array with values

Steve Schowiak
Greenhorn

Joined: Oct 21, 2002
Posts: 20
After creating a new array object, I want to load it with constant values. Being a COBOL programmer, I would make a sequential file with the values, and read them into the array. But I don't want to do this with JAVA. My program will eventually be an applet and won't be able to read in a sequential file (it's a DOS app now).
The answer is putting all the data in a class, and setting up the array in there. Now, I'm stuck with writing 625 lines of code that looks like:
MyArray[1][1] = 31;
MyArray[1][2] = 26;
.
.
.
MyArray[24][24] = 21;
There's got to be a more practical way of loading this array with constants other than this way or reading from external files.
But what is it?
Thanks. :roll:


I am not insane. The voices in my head told me so.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
int[][] foo = { { 1, 2, 3 }, { 4,5, 6} };
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Also, remember subscripts start at 0
so array[0][0] etc.


Author and Instructor, my book
 
GeeCON Prague 2014
 
subject: Loading 2-dimensional array with values