CSci 150: Foundations of computer science I
Home Syllabus Assignments Tests

printable version

Exam 2

[1] [2] [3] [4] [5] [6] [7] [8] [9]

Problem X2.1.

[12 pts] Complete the program so that it displays a triangle of asterisks as wide as the user indicates. The below example illustrates how the program should work when the user enters 5; if the user entered 2, the program would display just three asterisks across two lines. (You can assume the user enters an integer between 1 and 80.)

How big a triangle? 5
*****
****
***
**
*
public class StarTriangle extends Program {
    public void run() {
        int size = this.readInt("How big a triangle? ");