//       CS210 - Algorithms and Data Structures I
//            Department of Computer Science
//       National University of Ireland, Maynooth
//
//           Solutions to Self-help Exercises
//                     Tom Naughton
//                    November 2000
//
//-------------------------------------------------------
//http://www.cs.may.ie/tnaughton/cs210/cs210selfhelp.html
//=======================================================
class ExerciseV1 {

  public static void fn(int n) {

    int row;     // counter for rows
    int counter; // counter for characters

    /*
    ** Write out the upper triangle. This will entail, at each row,
    ** writing out (row) spaces and (n - row) stars.
    */
    row = 0;
    while(row < n){

      // write out the correct number of spaces
      counter = 0;
      while (counter < row) {
        System.out.print(' ');
        counter++;
      }

      // write out the correct number of stars
      counter = row;
      while (counter < n) {
        System.out.print('*');
        counter++;
      }

      System.out.println();
      row++;
    }

    /*
    ** Write out the lower triangle. This will entail, at each row,
    ** writing out (n-row-1) spaces and (row+1) stars.
    */
    row = 0;
    while(row < n){

      // write out the correct number of spaces
      counter = 0;
      while (counter < (n-row-1)) {
        System.out.print(' ');
        counter++;
      }

      // write out the correct number of stars
      counter = 0;
      while (counter < (row+1)) {
        System.out.print('*');
        counter++;
      }

      System.out.println();
      row++;
    }
  }

  public static void main(String args[]) {
    fn(4);
  }
}
