大数据第9周
1.Scala开发环境搭建
2.SCALA语言简介
2.1值和变量
变量:var
“值”类型声明后不可以更改数值,而“变量”类型可以。
2.3 String类型
3.Scala的表达式
3.1表达式的返回值
如果没有“{}”那就说明不是一句表达式,每一句表达式都会有返回。变量“resA”只是用来存储表达式的返回值。
3.2 if表达式
3.3 匹配表达式
object testScala { def main(args: Array[String]): Unit = { val x=10; val y=20 val max=x>y match{ case true =>println(s"Received data is $x.");x case false =>println(s"Received data is $y.");y } println(s"The max is $max.") } }
object testScala2 { def main(args: Array[String]): Unit = { var message="OK" val status = message match { case "OK" => 200 case other => { println(s"Couldn‘t parse $other") -1 } } println(s"status is $status") message="hhh" val status2 = message match { case "OK" => 200 case other => { println(s"Couldn‘t parse $other") -1 } } println(s"status2 is $status2") } }
object testScala3 { def main(args: Array[String]): Unit = { val response:String="OK" val res=response match{ case s if s!=null =>println(s"Received s is $s.");s case s =>println(s"Other $s"); } println(s"The res is $res.") } }
object testScala4 { def main(args: Array[String]): Unit = { val x:Int=12180 val y:Any=x val res=y match{ case x:String =>println(s"$x.");x case a:Float =>println(s"$a%.2f.");a case b:Double =>println(s"$b..2f.");b case c:Long =>println(s"${c}l.");c case d:Int =>println(s"${d}i.");d } println(s"The res is $res.") } }
3.4 循环(下次讲)
大数据Hadoop第九周——Scala开发环境搭建+Scala语言值变量类型表达式
原文:https://www.cnblogs.com/caiyishuai/p/12779272.html