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

Thread: I HAVE QUESTION ABOUT CREATING PYRAMID OF NUMBERS

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I HAVE QUESTION ABOUT CREATING PYRAMID OF NUMBERS

    I have a problem on how to make this output:
    Output1:
    ENTER NO.OF ROW/S: 5
    1112131415
    78910
    456
    23
    1

    Output2:
    ENTER NO.OF ROW/S: 4
    78910
    456
    23
    1

    I created a code below, but the output is like this:
    Output1:
    ENTER NO.OF ROW/S: 5
    12345
    6789
    101112
    1314
    15

    Output2:
    ENTER NO.OF ROW/S: 6
    123456
    7891011
    12131415
    161718
    1920
    21

    Code:
    Scanner in=new Scanner(System.in);
    int x,y,row,num=0;
    System.out.print("ENTER NO.OF ROW/S:");
    row=in.nextInt();
    for(x=1;x<=row;x++)
    {
    for(y=x;y<=row;y++)
    {
    num++;
    System.out.print(num);
    }
    System.out.println();
    }

    I'm newbie in java programming, what should I do to make that output possible? thanks in advance.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I HAVE QUESTION ABOUT CREATING PYRAMID OF NUMBERS

    what should I do to make that output possible
    Look at the output line by line and find the relationship between what is printed on a line, which line it is and the number of lines to be printed. When you find the relationship, then write pseudo code for an algorithm and then write the program code from that algorithm.
    You know the last line has a single 1 (1 number)
    and the next to the last line has 23 (2 numbers)
    Continue with the rest of the lines. How many numbers for how many lines? If 2 lines then 3 numbers.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Number Pyramid Question
    By t-rank in forum Loops & Control Statements
    Replies: 2
    Last Post: December 2nd, 2013, 08:44 AM
  2. [SOLVED] Rounding Decimal Numbers Question
    By Nuggets in forum Java Theory & Questions
    Replies: 5
    Last Post: March 19th, 2012, 04:12 PM
  3. Pyramid of Doubling Numbers
    By Override in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 29th, 2010, 10:01 PM
  4. help with a loop (pyramid of numbers)
    By ande6870 in forum Loops & Control Statements
    Replies: 2
    Last Post: October 7th, 2010, 08:17 PM
  5. help me .. about creating random numbers
    By soldier in forum Java Theory & Questions
    Replies: 2
    Last Post: December 20th, 2009, 08:24 PM