CS-151 Labs > Lab 1. The First Cup of Java


Part 1. Pyramids revisited

Add a new Java class to your project. This time, use lab1 as the package name. Use Pyramid as the name of the class and check the button for including a public static void main stub.

For your first more serious program, we want you to create a class called Pyramid that draws a simple 2D pyramid out of * characters. Your program will:

Here are some examples of inputs and outputs. (Recall from the Lab 0 that the way you provide command line arguments in Eclipse is from the Run As > Run Configurations… menu option and then click on the Arguments tab.)

input: 5
output:
    *
   ***
  *****
 *******
*********
input: 1
output:
*
No input
output: 
To run: java Pyramid <number>

You may want to spend a couple of minutes figuring out how many stars and how many spaces you would need to print on each line as a function of height and loop iteration variable.