Example: Christmas Tree

Write a program that takes a number n (1 ≤ n ≤ 100) and prints a Christmas tree with height of n+1.

Input Output Input Output
1   |  
* | *
2    |   
 * | * 
** | **
Input Output Input Output
3     |    
  * | *  
 ** | ** 
*** | ***
4      |     
   * | *   
  ** | **  
 *** | *** 
**** | ****

Hints and Guidelines

From the examples we see that the Christmas tree can be divided into three logical parts. The first part is the stars and the white spaces before and after them, the middle part is |, and the last part is again stars, but this time there are white spaces only before them. The printing can be done with only one loop and the new string(…) constructor, which we will use once for the stars and once for the white spaces.

Testing in the Judge System

Test your solution here: https://judge.softuni.bg/Contests/Practice/Index/512#6.

results matching ""

    No results matching ""