We had first hands on session on Scala 10 Sept,2009, a functional programming language, here is simple example which adds all numbers upto 1000 which are multiple of 3 or 5.
package test
object Example1 extends Application {
val answers =(1 until 1000).filter {eachNumber => eachNumber%3==0 || eachNumber%5==0}
val sum = answers.foldLeft(0) { _+ _ }
println(sum)
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment