Skip to content

Instantly share code, notes, and snippets.

@nemo-kaz
Created October 10, 2010 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemo-kaz/618993 to your computer and use it in GitHub Desktop.
Save nemo-kaz/618993 to your computer and use it in GitHub Desktop.
FizzBuzz.groovy
// 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
}
@Deadelven
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment