
Scala_1.控制台打印,变量定义,函数定义
发布日期:2021-05-07 00:19:20
浏览次数:7
分类:技术文章
本文共 1537 字,大约阅读时间需要 5 分钟。
Scala_1.控制台打印,变量定义,函数定义
package com.liusimport scala.util.control._object HelloWorld { def main(args: Array[String]): Unit = {//// printStr() //打印输出// variablePractice() //变量练习// strOperation() //字符串操作// println(functionName(12,5)) //函数操作 } /** * 打印练习 */ def printStr():Unit={ println("Hello World!") println(10) print("Hello World!") } /** * 变量练习 */ def variablePractice():Unit={ val x =10 var y = 10 y =20 val z:Int = 10 val a:Double = 1.0 val b:Double = 10.0 println("Hello World".length) println("Hello World".substring(2,6)) println("Hello World".replace("H","3")) println("Hello World".take(5)) //Hello println("Hello World".drop(5)) // World } /** * 字符串操作 */ def strOperation():Unit={ //s"" val n = 45 println(s"We have $n apples") val c = Array(11,9,6) println(s"My Second daughter is ${c(0)-c(2)} years old.") println(s"We have double the amount of ${n/2.0} in apples.") println(s"Power of 2:${math.pow(2,2)}") //f"" println(f"Power of 5:${math.pow(5,2)}%1.0f") println(f"Square of 122:${math.sqrt(122)}%1.4f") //raw"" println(raw"New line feed:\n.Carriage return:\r.") println("They stood outside the \"Rose and Crown\"") val html = """""" println(html) } /** * 函数练习 * @param a * @param b * @return */ def functionName(a:Int,b:Int):Int={// println(a+b) return a+b; }}
发表评论
最新留言
很好
[***.229.124.182]2025年03月22日 14时21分37秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Mybatis源码分析(四):属性接口之objectFactory
2019-03-03
全面了解 Nginx 主要应用场景
2019-03-03
最全的spring面试题和答案
2019-03-03
CentOS 8 已下载ntpdate 却无法使用crond进行时间同步
2019-03-03
Mybatis的这些坑!把我坑惨了!
2019-03-03
在 IntelliJ IDEA 中使用 Git,太方便了!
2019-03-03
7 个显著提升编码效率的IntelliJ IDEA必备插件
2019-03-03
企业API接口设计之token、timestamp、sign具体实现
2019-03-03
不懂别瞎搞!Redis 性能优化的 13 条军规!
2019-03-03
卸载 Navicat!事实已证明,正版客户端,它更牛逼……
2019-03-03
想彻底了解maven,有这篇文章足够了(中)
2019-03-03
Intellij IDEA 一些让人爱不释手的小技巧
2019-03-03
idea连接服务器远程调试(Dockerfile版)
2019-03-03
ElasicJob分布式定时任务
2019-03-03
feign调用上传文件接口(MultipartFile)
2019-03-03
centos 文件格式不对执行报错 || centos查看或者修改文件格式
2019-03-03
win锁屏界面用户名修改
2019-03-03
Java设计模式 —— 桥接模式(Bridge)
2019-03-03
计算机三级 信息安全技术历年真题(二)总共十套 3月底之前更完
2019-03-03
详解: 最小生成树
2019-03-03