Results 1 to 2 of 2
  1. #1
    billq is offline Member
    Join Date
    Dec 2009
    Posts
    25
    Rep Power
    0

    Default enhanced for loop

    Hello, is it possible to change the values of the array elements using the enhanced for loop. In the following I am trying to add 2 to each element in the array. When Println(i) it writes the original array. ;
    thanks

    int q[] = {1,2,3,4,5};

    for(int i : q)
    {
    i += 2;
    }
    for(int i : q)
    System.out.println(i);

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Enhanced For Loop
    By terahawks in forum New To Java
    Replies: 3
    Last Post: 04-16-2010, 08:46 AM
  2. Enhanced for loop in java
    By elizas in forum Java 2D
    Replies: 4
    Last Post: 03-29-2010, 05:43 PM
  3. Help for Enhanced for loop
    By jboy in forum New To Java
    Replies: 6
    Last Post: 09-13-2009, 06:45 AM
  4. Enhanced for loop
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-03-2007, 09:24 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
  •