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

Thread: problem in pyramid of number in java

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

    Question problem in pyramid of number in java

    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
    SW Missouri
    Posts
    20,069
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: problem in pyramid of number in java

    Please only post a question once. This question has been answered in the other post.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,260
    Thanks
    176
    Thanked 818 Times in 761 Posts
    Blog Entries
    5

    Default Re: problem in pyramid of number in java

    Thread locked. Duplicate of I HAVE QUESTION ABOUT CREATING PYRAMID OF NUMBERS

    Please read the forum rules.

Similar Threads

  1. [SOLVED] Number Pyramid Question
    By t-rank in forum Loops & Control Statements
    Replies: 2
    Last Post: December 2nd, 2013, 07:44 AM
  2. Perfect Number Java Loop Problem - Please Help!?
    By Th3T3chGuy in forum Loops & Control Statements
    Replies: 2
    Last Post: November 13th, 2011, 05:09 PM
  3. Need help on the pyramid number!
    By nicetan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 14th, 2011, 03:43 PM
  4. Pyramid of Doubling Numbers
    By Override in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 29th, 2010, 10:01 PM
  5. help with a loop (pyramid of numbers)
    By ande6870 in forum Loops & Control Statements
    Replies: 2
    Last Post: October 7th, 2010, 08:17 PM