CS 11 Fall 2005 -- Lab 3


Print a pattern! The code for this one is short, but getting it right may require some careful thought.


Printing a pattern

Your program should do something (seemingly) simple: Take a single number from the user, and then print a pattern to the screen. Now for the details...

First, ask the user for a single, positive (that is, non-negative and non-zero) integer. Your program should repeatedly request integer values until the user provides a positive one.

Given that integer (let's call it n, you will print a sequence of n "triangles" to the screen, where each triangle is composed of stars (that is, asterisk characters). The first triangle will be n x n, the second (assuming n > 1) will be (n-1) x (n-1), etc., down to the 1 x 1 triangle. So, if n = 4, then the output would be:

  *
  **
  ***
  ****

  *
  **
  ***

  *
  **

  *

As with lab-2, you should create a new directory named lab-3, change into it, and use Emacs to write your code in a new file named Triangles.java


Submitting your work

When your work is complete, you should submit it using the cs11-submit command, like so:

cs11-submit lab-3 Triangles.java

This lab is due on Thursday, September 29th at 11:59 pm!

Scott F. Kaplan
Last modified: Thu Sep 22 11:18:52 EDT 2005