标签:模式 asd dep div apply final span big 方法
快捷功能
-----------------------------------------------------------------------------------
补全 Tab键
粘贴模式 :paste,退出粘贴模式 ctrl + d
语法
------------------------------------------------------------------------------------
var 定义变量
val 定义常量,相当于java中的final,不能重复赋值
1 to 10 [ 1, 10 ]
1 until 10 [ 1,10 )
字符串求交集
scala> "hello".intersect("he") res31: String = he
BigInt类型
scala> var b = BigInt(999999999) b: scala.math.BigInt = 999999999 scala> b *= b //scala中没有 ++ 或 -- 语法 scala> b res33: scala.math.BigInt = 999999998000000001 scala> b *= b scala> b res35: scala.math.BigInt = 999999996000000005999999996000000001
导包
import scala.math._ //此处 _ 表示所有 sqrt(2) //开方 pow(2,3) //幂函数
apply方法,相当于索引
scala> "hello".apply(2) res40: Char = l scala> "hello"(2) res41: Char = l
scala中表达式都有值
scala> var x = 2 x: Int = 2 scala> var y = if(x > 0) 1 else -1 y: Int = 1 scala> var y = if(x < 0) -1 y: AnyVal = () scala> var p = println(123) 123 p: Unit = () //相当于null
最后一个表达式是整个语句的值
scala> var b = {print() ;234} warning: there was one deprecation warning; re-run with -deprecation for details ()b: Int = 234
输入
scala> var name = readLine("输入名字:") warning: there was one deprecation warning; re-run with -deprecation for details 输入名字:name: String = lasdjfonclnvlolfdgolsdfsadfs scala> name res43: String = lasdjfonclnvlolfdgolsdfsadfs
循环:while、for、for高级用法
break
scala> import scala.util.control.Breaks._ import scala.util.control.Breaks._ scala> for(i <- 1 to 10){ | println(i) | break} 1 scala.util.control.BreakControl scala>
标签:模式 asd dep div apply final span big 方法
原文地址:https://www.cnblogs.com/lybpy/p/9715223.html