Skip to content

Instantly share code, notes, and snippets.

@Sankame
Last active September 24, 2015 16:51
Show Gist options
  • Save Sankame/7f45c2231a524ad6e7a8 to your computer and use it in GitHub Desktop.
Save Sankame/7f45c2231a524ad6e7a8 to your computer and use it in GitHub Desktop.
メソッドと関数オブジェクト
import java.util._
object myapp {
//メソッド
def total(num: Int) = {
var res:Int = 0
for(n:Int <- Range(1,num + 1))
res += n
res
}
def main(args: Array[String]) = {
//関数オブジェクト
val total = (num: Int) => {
var res:Int = 0
for(n:Int <- Range(1,num + 1))
res += n
res
}
val rnd = new Random
val n = rnd.nextInt(100)
println(n + "までの合計:" + total(n))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment