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 › ARRAY HELP!!!!!!!!
Page Index Toggle Pages: 1
ARRAY HELP!!!!!!!! (Read 229 times)
ARRAY HELP!!!!!!!!
Nov 26th, 2008, 7:19pm
 
Hello!!


i'm doing an array of 8x8, 64 elements, and i have to assign them in groups of 8 elements, like this (0, 80, 160, 240, 320, 400, 480, 560, 0, 80, 160, 240...etc)

Can someone help me to make this array less longer?

int[] x = {0, 80, 160, 240, 320, 400, 480, 560, 0, 80, 160, 240,320,400,480,560,0,80,160,240,320,400,480,560,0,80,160,
240,320,400,480,560,0,80,160,240,320,400,480,560,0,80,160,
240,320,400,480,560,0,80,160,240,320,400,480,560,0,80,160,
240,320,400,480,560};


thanks a lot,

Rogo
Re: ARRAY HELP!!!!!!!!
Reply #1 - Nov 26th, 2008, 8:08pm
 
int u = 8; // array width and height
int[] x = new int[u*u];
int v = 0; // value
for(int i = 0; i < u*u; i++)
{
 x[i] = v%640;
 v = v+80;
 //println(x[i]);
}
Re: ARRAY HELP!!!!!!!!
Reply #2 - Nov 26th, 2008, 8:10pm
 
Well, Java1.5 solves most of the complications here, but here is the crude way of doing it:
int rowNum = 8;
int[] x = {0,1,2,3,4,5,6,7,8};

int s = x.length * rowNum;
int[] y = new int[s];

int k = 0;
for(int i = 0; i < rowNum; i++){
 for(int j = 0; j < x.length; j++){
   y[k++] = x[j];
 }
}


for(int i = 0; i < y.length; i++){
 println( y[i]);
}


Re: ARRAY HELP!!!!!!!!
Reply #3 - Nov 27th, 2008, 1:55am
 
thankss Seltar and Sw01.
your help will be return....
Cheesy
Page Index Toggle Pages: 1