Printing the Roof

After we have calculated the length of the roof we make a loop from 0 to roofLength. On each iteration we will:

  • Calculate the number of dashes we need to draw. The number will be equal to (n - stars) / 2. We write it down in a variable padding.

  • We print in the console: "dashes" (padding / 2 times) + "stars" (stars times) + "dashes" (padding / 2 times).

  • Before the iteration is over we add 2 to stars (the number of the stars).

It is not a good idea to add many character strings as it is shown above because this leads to performance issues. For more information visit: https://bg.wikipedia.org/wiki/%D0%9D%D0%B8%D0%B7#String_Builder

results matching ""

    No results matching ""