Allan Didier

Star Patterns

Goals

Write a Java program that prints various patterns of stars.

Skills

  • For loops

Program Details

Write a program (or programs) using for loops that will output the following patterns to the console. Ask the user how many rows they would like to print. Your program should print the patterns with the number of rows requested by the user. Your program will need to have for loops within for loops. The outer for loop will do the rows (down), the inner for loops will do the columns (left to right). The patterns below are shown for 5 rows. 

Pattern #1 (left aligned)

*
**
***
****
*****

Pattern #2 (right aligned)

       *
     **
    ***
  ****
*****

Pattern #3 (centered)

        *
      ***
    *****
  *******
*********

Pattern #4 (numbered and centered)
(This pattern will not display properly when you hit double digits. That is fine)

        1
      222
    33333
  4444444
555555555

 

Explanation and Comments:

This code is complex with loops within loops, loops starting and stopping at different points, and loops going forwards and backwards. In order for your project to be graded you need to comment each for loop and explain how it works. 

Resources