Created
September 10, 2014 10:31
-
-
Save petitviolet/6cfecff5a97104a7bd31 to your computer and use it in GitHub Desktop.
scala_fizzbuzz
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
object fizzbuzz { | |
def fizzbuzz(n: Int): Unit = { | |
} | |
def main(args: Array[String]) = { | |
val n: Int = args(0).toInt | |
for (i <- 1 to n){ | |
i match { | |
case i if i % 15 == 0 => println("fizzbuzz") | |
case i if i % 3 == 0 => println("fizz") | |
case i if i % 5 == 0 => println("buzz") | |
case _ => println(i) | |
} | |
} | |
} | |
} | |
object fizzbuzz1 { | |
def main(args: Array[String]) = { | |
val n: Int = args(0).toInt | |
(1 to n).foreach {i => | |
var output = "" | |
if (i % 3 == 0) { | |
output += "fizz" | |
} | |
if (i % 5 == 0) { | |
output += "buzz" | |
} | |
println(output match { | |
case "" => i | |
case _ => output | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment