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.
Re: I HAVE QUESTION ABOUT CREATING PYRAMID OF NUMBERS
Quote:
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.