Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: looping, for,while,do-while.

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default looping, for,while,do-while.

    can anyone please do this problem

    1 2 3 4
    2 4 6 8
    3 6 9 12
    4 8 12 16

    in for loop, while loop, and do-while,,

    ill study how this works in these three different structures of loop

    tnx a lot!!


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: looping, for,while,do-while.

    Hello chronoz13.

    I'm a bit confused... Can you please give me a little more detail?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: looping, for,while,do-while.

    oh sori sir..

    i've just red it on my school mate a while ago.

    it says

    do that program by using a loop(i dont remember all the details)

    but i think that

    the first number (number 1) will be initialized then it will increment up to (4). (THE FIRST ROW)

    1 2 3 4

    but im having some trouble formulating the idea on how to loop the next numbers ,(2nd 3rd and 4th row)

    2 4 6 8
    3 6 9 12
    4 8 12 16

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: looping, for,while,do-while.

    Are all these loops ment to be together as one or are you look for an example answer for each loop?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: looping, for,while,do-while.

        for(int i = 1; i <= 4; ++i) {
           System.out.print(i + " ");
        }
     
        System.out.println("");
     
        for(int i = 2; i <= 8; i += 2) {
           System.out.print(i + " ");
        }
     
        System.out.println("");
     
        for(int i = 3; i <= 12; i += 3) {
           System.out.print(i + " ");
        }
     
        System.out.println("");
     
        for(int i = 4; i <= 16; i += 4) {
           System.out.print(i + " ");
        }

    That should print what you want I guess.

    1 2 3 4
    2 4 6 8
    3 6 9 12
    4 8 12 16

    // Json

Similar Threads

  1. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM