Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that uses nested loops to create the following output shape: 1. 2. 3. 4. 5. Your program should be generalized to ask

image text in transcribed
Write a program that uses nested loops to create the following output shape: 1. 2. 3. 4. 5. Your program should be generalized to ask the user to input the number of output-lines. The hourglass shape shown above has nine (9) output lines. The input value provided by the user should always be a positive odd number or zero. Zero, an even number, or a negative number will cause the program to immediately exit. Note that the number of lines is also equal to the number of output stars (asterisks) on the first and last lines. Run your program for the input values-1, 1, 2, 7, 9, and 0 to demonstrate that it works properly The only print statements you are allowed to use are: System.out.print "Please enter an odd-number of output-lines (enter zero to exit the program): "; Systen.out-printf( *" ); // this is a single asterisk System , out, printf( " ); // this is a single blank System . out.print f( " ); // this is a new line

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

More Books

Students also viewed these Databases questions