import java.util.Scanner;
public class Pyramid {
public static void main (String [] args){
int numberOfLines;
numberOfLines = 8;
for (int row = 1; row <= numberOfLines; row++) {
for (int column = 1; column <= numberOfLines - row; column++)
System.out.print(" ");
for (int num = row; num >= 1; num--)
System.out.print((num >=10) ? " " + num : " " + num );
for (int num = 2; num <=row; num++)
System.out.print((num>= 10) ? " " + num : " " + num );
System.out.println();
}
}
}
The output should look like this:
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
(but in the pyramid shape)

New Topic/Question
Reply




MultiQuote






|