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

Thread: Re: Nested for loops

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nested for loops

    my output its come like
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    3
    3
    3
    3........
    pls help I cant find wht problem there in the codeing

    --- Update ---

    my output its come like
    1
    1
    1
    1
    1
    2
    2
    2
    2
    2
    3
    3
    3
    3........
    pls help I cant find wht problem there in the codeing


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Nested for loops

    Please post the code you are using and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: Nested for loops

    Quote Originally Posted by Norm View Post
    Please post the code you are using and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    import java.util.Scanner;
    class jag23
    {
    public static void main(String args[])
    {
    int n,num=1,c,d;
    Scanner in=new Scanner(System.in);
    System.out.println("Enter the number of rows of floyd's triangle you want");
    n=in.nextInt();
    System.out.println("Floyd's triangle");
    for(c = 1;c <= n;c++)
    {
    for(d = 1;d <= c;d++)
    {
    System.out.println(+num);
    num++;
    }
    System.out.println();

    }
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Nested for loops

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Make sure the code is properly formatted with indentations.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2013
    Posts
    45
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: Nested for loops

    Actually you made mistake on print statement.That is ,

    System.out.println(+num);

    you use "println". So "ln" means each time iterate the loop print statement is print next line.
    so that the output given only vertically

    So you used print instead of println like this..

    System.out.print(+num);

    this will print the correct Floyd's triangle.
    Regards
    Android developer
    Trinay Technology Solutions
    http://www.trinaytech.com
    5705750475

  6. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nested for loops

    what type of out put u want

Similar Threads

  1. Nested For Loops
    By javapol in forum Java Theory & Questions
    Replies: 10
    Last Post: February 22nd, 2013, 10:46 PM
  2. Nested for loops
    By Fordy252 in forum Loops & Control Statements
    Replies: 2
    Last Post: December 8th, 2012, 11:43 PM
  3. Nested for loops and array
    By bryanboy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 15th, 2011, 06:45 AM
  4. Using Nested Loops
    By m2msucks in forum Loops & Control Statements
    Replies: 7
    Last Post: November 5th, 2011, 07:05 PM
  5. Help with Nested Loops
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 03:31 PM