Question
Write a Java program which implements both the while and for loop, as needed, to draw the illustrations given below. Shape 1: 123456789 12345678 1234567
Write a Java program which implements both the while and for loop, as needed, to draw the illustrations given below.
Shape 1:
123456789
12345678
1234567
123456
12345
1234
123
12
1
Shape 2:
*************
*************
*************
*************
*************
Shape 3:
============
* *
* *
* *
* *
* *
============
Hint: To draw the shapes above, you can use nested for loops to accomplish the task. The outer for loop iterates on each row, and the inner for loop iterates on each column of current row.
Shape 1 has 9 rows and column is decreasing on each row.
for (int row=0; row { for (int col=1; col<=rowSize-row; col++) //for each column on current row { //display col number with a space } // display a new line } Shape 2 has 5 rows, 13 columns. for (int row=0; row { for (int col=0; col { //display } // display a new line }
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