Created
March 7, 2013 08:19
-
-
Save jkaihsu/5106408 to your computer and use it in GitHub Desktop.
Write a method print_triangle which takes at its input an integer representing the number of rows to print, and prints out a right triangle consisting of * characters, one line per row. For example, print_triangle(5) should print out:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_triangle(rows) | |
for j in 1..rows do | |
for i in 1..j do | |
print "*" * 1 | |
end | |
puts | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i just dont get how this works, yet it does