Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed 

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 1 24 2 1 1 248 16 8 4 21 1 2 4 8 16 32 16 8 4 2 1 1 2 4 8 16 32 64 32 16 84 2 1 1 2 4 8 16 32 64 128 64 32 16 8 4 2 1 Enter the number of lines: 12 1 2 1 2 44 2 1 1 2 816 8 4 2 1 1 2 48 16 32 16 8421 1 24816 32 64 32 16 8421 1 2 4 816 32 64 128 6432 16 8 421 1 2 48 16 32 64 128 256 128 64 32 16 8 4 21 1 2 48 16 32 64 128 256 512 256128 64 32 16 8 4 1 1 2 48 16 32 64 128 256 512 1024 512 256 128 64 32 16 8 4 21 1 2 48 16 32 64 128 256 512 1024 2048 1024 512 256 128 64 32 16 8 4 21 21

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions