# Array , Loop ?

• 08-15-2011, 06:49 PM
HearT.Hunt3r
Array , Loop ?
i have an array like this :
int[] vahid = {1,2,3,4,5,6,7}
i wanna use a loop to take numbers from vahid[1] to vahid[5] ... and assigned them to a variable..
how can i do that?
• 08-15-2011, 06:56 PM
Norm
Quote:

numbers from vahid[1] to vahid[5] ... and assigned them to a variable..
You'll only be able to assign one of the elements to the variable. The last one assigned will be the value that the variable has. The value of the first one will be replaced by the second one.
Are you wanted to sum those elements into the variable? something like this: var += anArray[ix];
Use a for loop with the starting i value = 1 and the ending value = 5.
• 08-16-2011, 11:23 AM
chinna
Quote:

Originally Posted by HearT.Hunt3r
i have an array like this :
int[] vahid = {1,2,3,4,5,6,7}
i wanna use a loop to take numbers from vahid[1] to vahid[5] ... and assigned them to a variable..
how can i do that?

Code:

```for(int i=o;i>=vahid .length'i++) {   System.out.println("Value "+vahid[i]); }```
• 08-16-2011, 11:41 AM
j2me64
do you mean

for(int i=0;i<vahid.length;i++)