Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading 2-dimensional array with values

 
Steve Schowiak
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int[][] foo = { { 1, 2, 3 }, { 4,5, 6} };
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, remember subscripts start at 0
so array[0][0] etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic