Q:

Write a Ruby program to create a new string which is n copies of a given string where n is a non-negative integer

0

 Write a Ruby program to create a new string which is n copies of a given string where n is a non-negative integer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ruby Code:

def multiple_string(str, n)
    return str*n
end
print multiple_string('a', 1),"\n"
print multiple_string('a', 2),"\n"
print multiple_string('a', 3),"\n"
print multiple_string('a', 4),"\n"
print multiple_string('a', 5),"\n"
Output:
a
aa
aaa
aaaa
aaaaa.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now