Question
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:
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:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started