CS 1713 Introduction to Computer Science -- Spring 2001
Practice Problem on Simple loops (while or for)

Write a Java program segment that will start with a integer n, and then will print a hollow triangle of stars of height n, as shown below for n == 10 and n == 5. (Assume that n > 1 The program needs to work for general n and not just 10 and 5.)

10            
*             
**             
* *     
*  *       
*   *      
*    *  
*     *
*      *
*       *
**********

5
*
**
* *
*  *
*****
If you wish, you may use the following helper method:

public void chars(int n, char ch) {
   for(int i = 0; i < n; i++)
      System.out.print(ch);
}

Here, chars(5, '*') will print 5 stars with no newline.