Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: Array , Loop ?

  1. #1
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default 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?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    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.
    HearT.Hunt3r likes this.

  3. #3
    chinna is offline Member
    Join Date
    Jul 2011
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by HearT.Hunt3r View Post
    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?
    Java Code:
    for(int i=o;i>=vahid .length'i++)
    {
       System.out.println("Value "+vahid[i]);
    }

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

Similar Threads

  1. how can i loop my array swap
    By belfast09 in forum New To Java
    Replies: 3
    Last Post: 06-15-2011, 04:35 AM
  2. Array or for loop? or both?
    By kedecr in forum New To Java
    Replies: 4
    Last Post: 03-09-2011, 01:24 PM
  3. Loop through Array in JSP
    By Robert_85 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-25-2010, 09:00 PM
  4. Finding a the max value of the array using a for loop
    By soccer_kid_6 in forum New To Java
    Replies: 1
    Last Post: 04-11-2010, 11:25 PM
  5. Replies: 2
    Last Post: 05-05-2008, 01:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •