算术操作(+-*/)
//加法
scala> var sum =1+2
sum: Int = 3
// 加法 第二个参数为Long 返回值为Long
scala> var sum =1+2l
sum: Long = 3
// 减法
scala> 1-2
res2: Int = -1
// 负数 操作
scala> 1+ -1
res3: Int = 0
// 乘法
scala> 1*2
res4: Int = 2
//乘法 第二个参数为Long 返回值为Long
scala> 1*2l
res5: Long = 2
// 除法
scala> 1/3
res0: Int = 0
// 取模
scala> 1%3
res1: Int = 1
关系操作
scala> 1>2
res6: Boolean = false
scala> 1<2
res7: Boolean = true
scala> 1!=2
res8: Boolean = true
scala> 1>=2
res9: Boolean = false
scala> 1<=2
res10: Boolean = true
逻辑操作
scala> var win=true
win: Boolean = true
//逻辑与
scala> win &&win
res11: Boolean = true
逻辑或
scala> win || win
res12: Boolean = true
scala> win && !win
res14: Boolean = false
对象比较
scala> var name="erhuan"
name: String = erhuan
scala> var passd="erhuan"
passd: String = erhuan
//scala 中比较的是内容 并非引用
scala> name == passd
res15: Boolean = true
网友评论