标签:scala
val hello = "Hello World" println(hello) //函数声明 def min(x:Int, y:Int):Int = { var a = x if(x > y) a = y return a } //===> println("min:"+min(3,5)) //3 //表达式函数声明 def max(x:Int,y:Int):Int = if(x>y) x else y //===> println("max:"+max(5,8)) //8 //while循环示例 var m = 3 while(m > 0){ print(m); if(m>1) print(",") else print("\n") m-=1 } //3,2,1 //for 示例 for(i <- 1 to 4) println("No."+i) // No.1 // No.2 // No.3 // No.4 val No = for(i <- 1 to 4) yield i println(No) //Vector(1, 2, 3, 4) val v2 = for(i <- "HELLO")yield i println(v2) //HELLO //两层循环,按照先递增i,再递增j的顺序 val v3 = for(i<-3 to 4;j<-1 to 2) yield(i+j) println(v3) //Vector(4, 5, 5, 6)
标签:scala
原文地址:http://power9li.blog.51cto.com/8267716/1585783