Java
UNIT CHALLENGES

separator-blank.png

CHALLENGE


separator-blank.png

CHALLENGE 1 – STAR PYRAMID

Write a program that uses nested for loops to output a pyramid as shown below.  The program should ask the user to provide the number of rows.  If that provided number is even, you should double up the middle row.

Sample output 1

 

     How many rows?

     7

 

     *

     **

     ***

     ****

     ***

     **

     *

 

Sample output 2

 

     How many rows?

     6

 

     *

     **

     ***

     ***

     **

     *

 

EXTRA CRITERIA (TO GET 100%)

 

Give the user the opportunity to specify if the pyramid should be sideways (like above) or normal.  See the sample output below.

 

Sample output

     How many rows?
     5

     Sideways or Normal?
     N

       *
      ***
     *****

 

separator-campeau.png