Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2012
    Location
    Dublin
    Posts
    21
    Rep Power
    0

    Default Quick Array explanation

    Hi I found this piece of code in my lecturers notes and would like to know how the output arrises

    Java Code:
    static void incAll(int[] b) {
         for (int i=0; i<b.length; i++)
          b[i]++;
    }
    .....
    
    int[] c = {5, 7, 9};
    incAll(c);
          System.out.println(c[0] + " " + c[1] + " " + c[2]);
    The output is 6, 8, 10

    I'm finding it hard to see where the +1 is coming from.

    Any info is much appreciated,
    Cheers..

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Quick Array explanation

    Quote Originally Posted by ManInTheMiddle View Post
    I'm finding it hard to see where the +1 is coming from.
    From the incAll method -> b[i]++; -> b[i] = b[i] + 1;

  3. #3
    Join Date
    Mar 2012
    Location
    Dublin
    Posts
    21
    Rep Power
    0

    Default Re: Quick Array explanation

    Cheers dude,

    I was thinking it was doing an increment again..

Similar Threads

  1. Implementing quick sort on a array of strings.
    By syle_q in forum New To Java
    Replies: 3
    Last Post: 03-27-2012, 03:58 AM
  2. Replies: 5
    Last Post: 11-27-2010, 12:28 AM
  3. need explanation
    By marie in forum New To Java
    Replies: 2
    Last Post: 03-21-2010, 03:35 PM
  4. Quick Sort explanation.
    By hawaiifiver in forum New To Java
    Replies: 4
    Last Post: 03-10-2009, 02:28 AM
  5. need a little explanation
    By cew27 in forum New To Java
    Replies: 7
    Last Post: 12-13-2007, 11:39 PM

Tags for this Thread

Posting Permissions

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