Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that will print a pyramid of integers to the screen. The program should begin by asking the user for the number

Write a java program that will print a pyramid of integers to the screen.

The program should begin by asking the user for the number of lines to be printed. The user is expected to enter a number from 1 to 9. As long as the user does not enter a number from 1 to 9, the program should continue asking for a number from 1 to 9.

Once a correct number has been entered, the program should print a pyramid of integers as shown in the examples below.

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's inputted values are shown below in italics:

Enter the number of lines (1-9): 7 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 7

Here is another example run:

Enter the number of lines (1-9): 0 Enter the number of lines (1-9): 10 Enter the number of lines (1-9): 4 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4

Technical Notes & Hints:

You will need to use several loops to complete this program - some of them are nested.

Use a loop to keep asking the user to enter the number of lines, until a correct number has been entered.

Use a loop to count through the number of lines to be printed. Inside this loop, use several nested loops to:

Print the correct number of spaces at the beginning of the line

Print the numbers starting at the current line number and counting down to 1

Print the numbers from 1, and counting back up to the current line number

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago

Question

4. Explain the characteristics of successful mentoring programs.

Answered: 1 week ago