Skip to content

Instantly share code, notes, and snippets.

@miguelsaddress
Created March 6, 2016 14:24
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 miguelsaddress/db91ac43ed447763ceb4 to your computer and use it in GitHub Desktop.
Save miguelsaddress/db91ac43ed447763ceb4 to your computer and use it in GitHub Desktop.
Scala FizzBuzz implementation
import scala.util.Try
object FizzBuzz {
def main(args: Array[String]): Unit = {
val iterations = Try(args(0).toInt).getOrElse(0)
(1 to iterations).foreach {i =>
if (i % 15 == 0) println(s"$i - FizzBuzz")
else if (i % 3 == 0) println(s"$i - Fizz")
else if (i % 5 == 0) println(s"$i - Buzz")
else println(s"$i")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment