环境配置

IDE: https://www.jetbrains.com/idea/

子雨大数据之Spark入门教程(Scala版)

/* implement */

语言特性

Online compiler: https://scastie.scala-lang.org/

只记录 “不太一样” 的特性。

一、常量变量

常量 val, 变量 var。

二、循环

var name = "hello"
for (n <- name)
{
  println(n)
}

嵌套循环,遍历数字和数组元素。

  def main(args: Array[String]): Unit = {

    for (a <- 1 to 10) {
for (b <- 1 to 10) {
if (a == b) {
println("a = " + a + ", b = " + b)
}
}
}

//嵌套循环的等价新写法
for (a <- 1 to 10; b <- 1 to 10 if a == b) {
...
}
val arr = Array[Int](1,2,3,4,5)
for(elem <- arr) {
println(elem1)
}
}

until 则不包括最后一个元素。

    val arr = Array[Int](1,2,3,4,5)
val arr1 = new Array[Int](arr.length)
for (index <- 0 until arr.length) {
arr1(index) = arr(index) + 10
} println(arr1.toBuffer)

类似与lambda的写法。

    val arr = Array[Int](1,2,3,4,5)
val ret = for (a <- arr) yield a + 10
println(ret.toBuffer)

三、条件赋值

支持混合表达。

  def main(args: Array[String]): Unit = {

    val x = 1
val y = if (x > 0) 1 else -1
println(y) val m = if (x > 2) 1
println(m) val n = if (x > 2) 1 else ()
println(n) val k = if (x < 0) 0 else if (x >= 1) 1 else -1
print(k)
}

四、函数

  def ml(a: Int, b: Int): Unit = {
println("hello, " + (a+b))
} def main(args: Array[String]): Unit = {
// 1.匿名函数
val f1 = (a:Int, b: Int) => a + b
println(f1(10, 20)) // 2.普通函数
ml(10,20) }

/* implement */

[Spark] Scala programming - basic level的更多相关文章

  1. PAT basic level 1001-1019 解题笔记

    1002 写出这个数 采用字符串输入数据,再对每位减去字符‘0’,得到该位相应的整数 int len=s.length();//字符串的长度 ; ;i<len;i++)//每位减去‘0’,逐位相 ...

  2. C#版 - PAT乙级(Basic Level)真题 之 1024.科学计数法转化为普通数字 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. PAT Bas ...

  3. C#版 - PAT乙级(Basic Level)真题 之 1021.个位数统计 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - P ...

  4. PAT (Basic Level) Practise (中文)-1039. 到底买不买(20)

    PAT (Basic Level) Practise (中文)-1039. 到底买不买(20) http://www.patest.cn/contests/pat-b-practise/1039 小红 ...

  5. PAT (Basic Level) Practise (中文)- 1022. D进制的A+B (20)

    PAT (Basic Level) Practise (中文)-  1022. D进制的A+B (20)  http://www.patest.cn/contests/pat-b-practise/1 ...

  6. PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)

    PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...

  7. PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)

    PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)   http://www.patest.cn/contests/pat-b-practise/1025 ...

  8. PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)

    PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)    http://www.patest.cn/contests/pat-b-practise/10 ...

  9. PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20)

    PAT (Basic Level) Practise (中文)-1027. 打印沙漏(20)  http://www.patest.cn/contests/pat-b-practise/1027 本题 ...

随机推荐

  1. PAT Basic 1095 解码PAT准考证 (25 分)

    PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级:B 代表乙级: 第 2~4 位是考场编号,范围从 101 到 999: 第 5~10 位是考试日期,格式为年.月. ...

  2. VLC 可能的 XML parser error 解决

    由于 VLC 设置不当 (通常是动了 skin 选项……),再次加载时 VLC 不能正常启动,并报如下错误: [00007f7dd003b670] xml xml reader error: XML ...

  3. Appium Desired Capabilities-iOS Only

    Appium Desired Capabilities-iOS Only These Capabilities are available only on the XCUITest Driver an ...

  4. js动画fireworks烟花

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. Kubernetes1.16下部署Prometheus+node-exporter+Grafana+AlertManager 监控系统

    Prometheus 持久化安装 我们prometheus采用nfs挂载方式来存储数据,同时使用configMap管理配置文件.并且我们将所有的prometheus存储在kube-system #建议 ...

  6. hdu4612 Warm up[边双连通分量缩点+树的直径]

    给你一个连通图,你可以任意加一条边,最小化桥的数目. 添加一条边,发现在边双内是不会减少桥的.只有在边双与边双之间加边才有效.于是,跑一遍边双并缩点,然后就变成一棵树,这样要加一条非树边,路径上的点( ...

  7. unity vulkan snapdragon profiler

    your device does not match the hardware requirements of this application 遇到上面那个warning 跟了下 是vulkan c ...

  8. 【转载】解决繁体、日文游戏乱码的五种方法 转载自:http://tieba.baidu.com/p/488627981

    方法1:转换区域 开始——设置——控制面板——区域和语言选项——分别选择“高级”和“区域选项”标签——在其下拉框中都选择“日语”(或“日本”)(选项有点多,慢慢找)——重启后即可生效. *某影注:日语 ...

  9. django + ckeditor + 七牛云,图片上传到七牛云

    传送门 本人使用的是 Django 的自带的管理后台,安装 ckeditor 富文本编辑器后,上传图片的时候直接传到七牛云的.

  10. 使用yum命令出错:SyntaxError: invalid syntax 由于用户取消而退出

    详见: https://blog.csdn.net/qq_24880013/article/details/90731617 必须修改的两个yum配置文件: 因为yum使用python2,因此替换为p ...