CS 11 Fall 2004 -- 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 30th at 11:59 pm!

Scott F. Kaplan
Last modified: Fri Sep 24 10:34:28 EDT 2004