Exercise 1C - Triangle Printing Program
Write a program that takes a number from the user and then prints a triangle
of stars of that height. It then asks the user whether they want another triangle.
- e.g.
-
Triangle Printing Program
=========================
Please enter desired height of triangle: 3
*
**
***
Another one? yes
Please enter desired height of triangle: .....
Hints
You should remember:
- that the class name needs to be the same as the filename.
(so if you call your class Triangle, then it needs to be saved in Triangle.java)
- to use the public static void main( String argv[] ) method.
- to look at the number guessing program for hints on how to read numbers from the keyboard.
- that you should be using a couple of loops to print out the triangle.
- to lay out your code neatly - doing it in xemacs will automatically lay it out acceptably.
- to comment your code (preferably in the javadoc
style used above).
Extras
Try changing the program so that the triangle of stars is centred on the screen:
- e.g.
-
*
***
*****
