scala 入门1、变量声明1、不可变型 val a = “小明” 2、可变型var a:String = “小明” var a = “小明” 2、Scala的值类型有7中同java的8大基本数据类型。少了一个boolean byte short int long double float char3、for循环数字循环for(i<- i to 10){ println(i)}打印1 - 10;数组循环var arr = Array("java","scala","c#");for(i<- arr){ println(i) }4、方法和函数方法 声明:def ml(x: Int,y: Int) :Int = x +y; 调用:ml(3,4) 结果:7函数 声名:val f1 = (x:Int,y:Int)=>x+y f1(2,3) 结果:55、数组val arr = Array(1,2,3);val arr1 = ArrayBuffer();可变的数组6、映射val map1 = Map("scala"->1,"java"->2);val map2 = Map(("scala","1"),("java","2"));
|