Quick Java question

Discussion in 'Mac Programming' started by Dr. No, May 4, 2005.

  1. macrumors regular

    Joined:
    Sep 13, 2003
    #1
    Can anyone here tell me what the Java shortcut "+=" does?

    As in:

    int term = 1;
    int sum = 0;

    sum += term;




    Thanks- I am preparing for my computer science final :)
     
  2. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    it adds the operand on the right to the operand on the left and reassigns the result to the left.

    in your example, its the same as

    sum = sum + term;
     
  3. Moderator emeritus

    grapes911

    Joined:
    Jul 28, 2003
    Location:
    Citizens Bank Park
    #3
    sum += term; is short for:

    sum = sum + term;


    Edit: too slow :eek:
     

Share This Page