Objectives |
Students use a for loop to
solve a counted loop problem. |
Background |
This program will display various patterns
of stars ('*') that will require the creative use of
iteration and decisions. |
New Terms |
|
Materials |
Download
Stars.java. |
Submission |
|
Acknowledgment |
Adapted
from an original lab by Arch Harris & Nancy Harris |
Part 4 - Pattern A
**********
*********
********
*******
******
*****
****
***
**
*
The leftmost stars are in the leftmost output column. Test your code with an odd number of stars and an even number of stars.
HINT: Again think about the relationship between the number of rows, what row you are on and the number of starts to display.
Part 5 -Pattern B
*
**
***
****
*****
******
*******
********
*********
**********
The leftmost star of the last row is in the first position of the output column.
HINT: You used starCnt in the example pattern and pattern A. You should think about using a spaceCnt variable as well to "display" the right number of spaces. How many for loops will you have for this part of the problem?
Also, while developing the code, replace space which is "hidden", with another character which is visible. This will help you to see what is happening in the code.
Part
6 - Pattern C
**********The top row, leftmost star is in the first position of output.
*********
********
*******
******
*****
****
***
**
*
Also, while developing the code, replace space which is "hidden", with another character which is visible. This will help you to see what is happening in the code.
Optional Part 7 - Pattern D - Bragging Rights
*Note, the pattern is defining the number of rows. For an odd number of rows, you would only have one middle line. The middle row leftmost star is in the first position of the output.
***
*****
*******
*********
*********
*******
*****
***
*
updated 10/20/2013 - NLH