Skip to content

Instantly share code, notes, and snippets.

@monksy
Created April 26, 2018 03:10
Show Gist options
  • Select an option

  • Save monksy/3e65efeb1a0ce68c33ac5bcbe02fe8bd to your computer and use it in GitHub Desktop.

Select an option

Save monksy/3e65efeb1a0ce68c33ac5bcbe02fe8bd to your computer and use it in GitHub Desktop.
Fizzbuzz in scala
def fizzBuzz(number: Int): String = {
number match {
case z if z % 3 == 0 && z % 5 == 0 => "Fizzbuzz"
case z if z % 3 == 0 => "Fizz"
case z if z % 5 == 0 => "Buzz"
case _ => number.toString
}
}
(1 to 100).foreach(a=> println(fizzBuzz(a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment