For Loop

Discussion in 'Java' started by netOwen, Nov 29, 2016.

  1. netOwen

    netOwen

    Joined:
    Nov 28, 2016
    Messages:
    2
    Likes Received:
    0
    I am wonder if someone could explain to me, how this for loop works.

    public class DoWhat
    {
    public static void main(string[] args)
    {
    int x = 0;
    int i;
    for ( i = 1; i <=4; i++)
    {
    x = x + (i*i +3);
    System.out.printf("%4d %4d\n", i,x);
    }// end of loop
    }//end main
    } //end class DoWhat

    i know that the output is

    1 4
    2 11
    3 23
    4 43

    how dose it come to this out put??
     
    netOwen, Nov 29, 2016
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Loop the loop...

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,704
    Karl Seguin
    Feb 16, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,578
    Tim Slattery
    Mar 30, 2005
  3. -
    Replies:
    12
    Views:
    1,056
    Remon van Vliet
    Jun 15, 2005
  4. Byte
    Replies:
    4
    Views:
    685
    adam.deprince@gmail.com
    Mar 24, 2006
  5. Daniel Pitts
    Replies:
    14
    Views:
    1,623
    Patricia Shanahan
    Dec 23, 2006
  6. Isaac Won
    Replies:
    9
    Views:
    865
    Ulrich Eckhardt
    Mar 4, 2013
  7. prayercall

    background image for each page

    prayercall, May 11, 2016, in forum: HTML and CSS
    Replies:
    1
    Views:
    691
    Exodus_AU
    May 16, 2016
  8. Jose Concepcion

    Text Adventure Game (for Steam)

    Jose Concepcion, Jun 29, 2016, in forum: Introductions
    Replies:
    0
    Views:
    547
    Jose Concepcion
    Jun 29, 2016
Loading...