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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!