Question: 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
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
Get step-by-step solutions from verified subject matter experts
