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
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 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,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: problem in pyramid of number in java

    Thread locked. Duplicate of http://www.javaprogrammingforums.com...d-numbers.html

    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, 08:44 AM
  2. Perfect Number Java Loop Problem - Please Help!?
    By Th3T3chGuy in forum Loops & Control Statements
    Replies: 2
    Last Post: November 13th, 2011, 06: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