變數申明 值型別表示式陣列等
阿新 • • 發佈:2018-12-14
1. val a=1 val a=”a” 2. for(i<-arr) println(i) 3. for(i<-1 to 3;j<-1 to 3 if(i!=j)) println(i*10+j) 4. val res=for(i<-1 until 10) yield i val res=for(i<-1 to 10) yield i 5. 1+2;1+3.3 6. def test(x: Int, y: Int): Int=x*y val f1=(x:Int,y:Int)=>x+y def m1(f:(Int,Int)=>Int)=f(3,4) m1(f1) 7. val f1= m1 _ 8. val arr=new Array[Int](8) val arr=Array("java","scala") val arr=ArrayBuffer[Int]() 9. println(arr.toBuffer) 10. arr+=(2,3,4,5) 11. arr++=Array(2,3,4,5) 12. arr2++=ArrayBuffer(8,9,10,11) 13. arr2.insert(0,0,23) 14. arr2.remove(1,1) 15. for(i<-arr3) println(i) 16. for(i<-0 until arr3.length) println(i) 17. for(i<-0 until arr3.length) println(arr3(i)) 18. for(i<-(0 until arr3.length).reverse) println(arr3(i)) 19. val res=for(i<-arr3) yield i*10 20. res.sum res.max res.sorted