Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I. Write a JAVA program that use a nested for-loop (for-loops in a for-loop) to create the following output hourglass shape: 1. Your program should

I. Write a JAVA program that use a nested for-loop (for-loops in a for-loop) to create the following output hourglass shape:image text in transcribed

1. 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.

2. 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.

3. Note that the number of lines is also equal to the number of output stars (asterisks) on the first and last lines.

4. Run your program for the input values 1, 1, 2, 7, 9, and 0 to demonstrate that it works properly.

5. 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): " ); System.out.print('*'); // this is a single asterisk System.out.print(' '); // this is a single blank System.out.println(); // this is a new line

II. Now attempt this bowtie using nested loops:

image text in transcribed

Your program should generate the bowtie for any positive odd number of output lines. The above example has 7 output lines

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions