We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Populating 2D Arrays
Page Index Toggle Pages: 1
Populating 2D Arrays (Read 537 times)
Populating 2D Arrays
Apr 20th, 2007, 8:43am
 
Forgive the simple question; it's been a while since I've done this, and Google isn't revealing the answer.  

I am trying to declare, then populate a 2D array with integers.  I've tried several variations of what is pasted below to little success.  Can some kind soul advise on proper syntax?  (Thanks.)

Code:

// - - - - - Attempt 1 - - - - -

int[][] panels = new int[15][4];

panels [][]=
{ 6,6,0,0,0,0,0,0 };
{ 7,8,0,0,0,0,0,0 };
{ 8,9,0,0,0,0,0,0 }; ...

// - - - - - Attempt 2 - - - - -

int[][] panels = new int[15][4];

panels [0][]={ 6,6,0,0,0,0,0,0 };
panels [1][]={ 6,6,0,0,0,0,0,0 };
panels [2][]={ 6,6,0,0,0,0,0,0 };
panels [3][]={ 4,4,4,0,0,0,0,0 };...
Re: Populating 2D Arrays
Reply #1 - Apr 20th, 2007, 9:41am
 
1: You're geting your numbers the wrong way around [15][4] means 15 4-digit arays, not 4 15-digit arrays.

2: You ned some extra keywords/less [] in places.

Code:
int[][] a=new int[3][4];
a=new int[][]{ {1,2,3,4},{2,3,4,5},{3,4,5,6}};

int[][] b=new int[3][4];

b[0]=new int[]{1,2,3,4};
b[1]=new int[]{2,3,4,5};
b[2]=new int[]{3,4,5,6};
Re: Populating 2D Arrays
Reply #2 - Apr 24th, 2007, 6:46am
 
JohnG,

It worked.  Thank you.

JasonV
Page Index Toggle Pages: 1