Created
October 10, 2010 05:28
-
-
Save nemo-kaz/618993 to your computer and use it in GitHub Desktop.
FizzBuzz.groovy
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
// g100pon #61 FizzBuzz | |
1.upto(100) { | |
ans ="" | |
if (it%3 == 0) {ans ="Fizz"} | |
if (it%5 == 0) {ans += "Buzz"} | |
if (ans == "") {println it} else println ans | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1.upto(100) {num ->
def fbString = ""
fbString += (num % 3 == 0) ? "Fizz" : ""
fbString += (num % 5 == 0) ? "Buzz" : ""
fbString = (fbString == "") ? "${num}" : fbString
println fbString}
If one ever wants to use Ternary Operators