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?
Printable View
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?
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.Quote:
numbers from vahid[1] to vahid[5] ... and assigned them to a variable..
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.
do you mean
for(int i=0;i<vahid.length;i++)