Created
August 24, 2014 10:31
-
-
Save ara-ta3/041b7fd799dc6df2a17f 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
package com.main | |
object Fizzbuzz { | |
def main(args:Array[String]){ | |
this.run(15).zipWithIndex foreach { | |
case(x,i) => println( (i+1) + " : " + x) | |
} | |
} | |
def run(max:Int):Seq[String] = { | |
var ret:Seq[String] = Seq.range(1,max+1).map{ | |
n => if(n%15 == 0) "fizzbuzz" | |
else if(n%3 == 0) "fizz" | |
else if(n%5 == 0) "buzz" | |
else n.toString() | |
} | |
ret | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment