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 4 of 4

Thread: Nested For Loop!

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Nested For Loop!

    can someone plz tell me how this nested for loop is generating this output...

    class Nested {
    public static void main(String args[]) {
    int i, j;
    for(i=0; i<10; i++) {
    for(j=i; j<10; j++)
    System.out.print(".");
    System.out.println();
    }
    }
    }

    ..........
    .........
    ........
    .......
    ......
    .....
    ....
    ...
    ..
    .


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Nested For Loop!

    Quote Originally Posted by samadniz View Post
    can someone plz tell me how this nested for loop is generating this output...
    First it may be instructive for you to tell us your thoughts on the matter. If you're not sure, consider walking through the code line by line as if you're the Java Virtual Machine and were executing the code yourself. If you run into a for loop, then loop that many times, changing your for loop index as you loop. This may not only provide you with your answer, but some good insights into how Java works as well.

    Edit: why the H did you re-post the same question that you've already posted previously? You didn't even read or follow Norm's recommendations. If your goal is to annoy us, congratulations, you've succeeded.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nested For Loop!

    Hahaha, I dnt wanna annoy any one, And thx for your encouragement....

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Nested For Loop!

    Quote Originally Posted by samadniz View Post
    can someone plz tell me how this nested for loop is generating this output...

    class Nested {
    public static void main(String args[]) {
    int i, j;
    for(i=0; i<10; i++) {
    for(j=i; j<10; j++)
    System.out.print(".");
    System.out.println();
    }
    }
    }

    ..........
    .........
    ........
    .......
    ......
    .....
    ....
    ...
    ..
    .
    That code will not produce that output. Check your code and post again. Put [code=java] before your code and [/code]after your code.

    Dont forget to read the forum rules to avoid "annoying" people.

Similar Threads

  1. How is this nested for loop working!
    By samadniz in forum Member Introductions
    Replies: 2
    Last Post: September 3rd, 2012, 09:59 AM
  2. Nested for loop
    By wolf_fcknHaley33 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 23rd, 2012, 08:49 AM
  3. Need help with java gui and nested for loop
    By gatorsgirl in forum Loops & Control Statements
    Replies: 11
    Last Post: March 24th, 2012, 12:35 PM
  4. Nid help in nested loop !!
    By Spice in forum Loops & Control Statements
    Replies: 1
    Last Post: February 14th, 2012, 11:10 AM
  5. nested loop
    By b109 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 30th, 2010, 10:05 AM