Created
January 12, 2013 04:24
-
-
Save kmandreza/4516081 to your computer and use it in GitHub Desktop.
Write a method called fizzblam that prints the numbers from 1 to 1000. But for multiples of 5 print “Fizz” instead of the number and for the multiples of 7 print “Blam”. For numbers which are multiples of both 5 and 7 print “FizzBlam.”
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 fizzblam | |
1000.times do |n| | |
if (n+1) %7 == 0 && (n+1) %5 == 0 | |
puts "FizzBlam" | |
elsif (n+1) %5 == 0 | |
puts "Fizz" | |
elsif (n+1) %7 == 0 | |
puts "Blam" | |
else | |
puts n + 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment