标签:
def main(args: Array[String]): Unit = {
for (i <- 1 to 2; j <- 1 to 2 if i != j)
println((100 * i + j) + " ");
}
|
102
201
|
def addA(x: Int) = x + 100
println("The result from a function is :" + addA(2))
|
The result from a function is :102
|
def main(args: Array[String]): Unit = {
val add = (x: Int) => x + 200
println("The result from a val is " + add(2))
}
|
The result from a val is 202
|
def main(args: Array[String]): Unit = {
def fac(n:Int): Int = if (n <= 0) 1 else n * fac(n - 1)
println("The result from a fac is : " + fac(10) )
}
|
The result from a val is : 3628800
|
def main(args: Array[String]): Unit = {
def combine(content: String, left: String = "[", right: String = "]") = left + content + right
println("The result from a combine is : " + combine("I love Spark", "@", "@"))
}
|
The result from a combine is : &I love Spark&
|
def main(args: Array[String]): Unit = {
def connected(args: Int*) = {
var result = 0
for(arg <- args) result += arg
result
}
println("The result from a connected is : " + connected(1,2,3,4,5) )
println("The result from a connected is : " + connected(1,2,3,4,5,6) )
}
|
The result from a connected is : 15
The result from a connected is : 21
|
import scala.io.Source
object Test {
def main(args: Array[String]): Unit = {
lazy val file = Source.fromFile("e:\\userx.txt")
println("Scala");
// for (line <- file.getLines()) {
// println(line);
// }
}
}
|
DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。 Scala 深入浅出实战经典(1-64讲)完整视频、PPT、代码下载: 百度云盘:http://pan.baidu.com/s/1c0noOt6 腾讯微云:http://url.cn/TnGbdC 360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2
04Scla学习:For与Function进阶实战、Lazy的使用
标签:
原文地址:http://www.cnblogs.com/wangshuo1/p/4679848.html