# Number Pyramid Question

• October 18th, 2010, 12:24 AM
t-rank
Number Pyramid Question
i have been working on this program for like 4 hours and i just cannot come up with a solution...i do know that loops have to be used...

Problem:
Write a program that prompts the user to enter an intger from 1 to 15 and displays a pyramid, as shown in the following sample run:

Enter the number of lines: 7
______1
_____212
____32123
___4321234
__543212345
_65432123456
7654321234567

those are suppose to be spaces instead of underscores...its only way i could make it look right on this post

i have got the right side of it, but i'm stuck on how to get the left side.

Code java:

import java.util.Scanner;
public class pyramid {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("enter lines: ");
int k = input.nextInt();

for (int i=1; i<=k; i++){
for (int j=1; j<=i; j++){
System.out.print(" " +j);}
System.out.print("\n");
}
}
}

• December 2nd, 2013, 06:31 AM
racoonic
Re: Number Pyramid Question
Quote:

Originally Posted by t-rank
i have been working on this program for like 4 hours and i just cannot come up with a solution...i do know that loops have to be used...

Problem:
Write a program that prompts the user to enter an intger from 1 to 15 and displays a pyramid, as shown in the following sample run:

Enter the number of lines: 7
______1
_____212
____32123
___4321234
__543212345
_65432123456
7654321234567

those are suppose to be spaces instead of underscores...its only way i could make it look right on this post

i have got the right side of it, but i'm stuck on how to get the left side.

Code java:

import java.util.Scanner;
public class pyramid {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("enter lines: ");
int k = input.nextInt();

for (int i=1; i<=k; i++){
for (int j=1; j<=i; j++){
System.out.print(" " +j);}
System.out.print("\n");
}
}
}

....
I omitted the scanner part.
• December 2nd, 2013, 07:44 AM
GregBrannon
Re: Number Pyramid Question
@racoonic: Please don't post solutions (2x).