Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the output should be like the following. Write a program using a Scanner that asks the user for a number n between 1 and 9

image text in transcribed
the output should be like the following.
image text in transcribed
Write a program using a Scanner that asks the user for a number n between 1 and 9 (inclusive). The program prints a trianigle with 2n 1 rows. The first row contains only the square of 1 , and it is right-justified. The second row contains the square of 2 followed by the square of 1 , and is right justified. Subsequent rows include the squares of 3,2, and 1 , and then 4,3,2 and 1 , and so forth until n rows are printed. Starting at row n+1, the squares between (n1) to 1 are printed, again right justified. Row n+2 prints the squares between (n -2) to 1 . Notes - Your solution should NOT use the conditionaloperator. - Your solution should NOT use tabs - Your solutions SHOULD have at least one nested loop Hint Don't think of the output as a triangle. Think of it as two rectangular tables: one of the first n rows, the second of the last (n-1) rows: Within each table, some cells are three spaces, some are one space and two digits, and some are two spaces and one digit. Start by printing an entire table with each cell its appropriate square value. Then figure out how to replace the cells that should "empty" with three spaces instead of a number. Finally, figure out how to print the one-digit numbers as two spaces and one digit, and the two-digit numbers as one space and two digits. Enter a number between 1 and 9 inclusive: 9 1411619441125169413625169414949363625251616994411816449362516941644949363625251616994411362516941251616994411941

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Which are non projected Teaching aids in advance learning system?

Answered: 1 week ago