Question: Write program in Java that produces the number pyramids as shown below: The programs must prompt the user for how many lines to generate. Your
Write program in Java that produces the number pyramids as shown below:
The programs must prompt the user for how many lines to generate. Your program must be able to generate properly formatted output regardless of the number of lines requested. Notice that the formatting of the output is based upon the maximum number generated in each of the pyramids. The number generated will not be larger than a Long.
You can convert a number to a string like: String str = "" + value;
The format specifier for formatted output (System.out.printf) can be a String variable. You'll need to do this to make sure the output is formatted based on the size of the numbers.
Enter the number of lines: 8 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4 5 43 2 1 2 3 4 5 6 5 4 3 212 3 4 5 6 7654 3 2 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 2 3 4 5 6 78 Enter the number of lines: 10 7 6 5 4 3 2 1 2 3 4 5 6 7 10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
