博客
关于我
Scala_1.控制台打印,变量定义,函数定义
阅读量:300 次
发布时间:2019-03-04

本文共 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 =      """       

Press belo',Joe

""" println(html) } /** * 函数练习 * @param a * @param b * @return */ def functionName(a:Int,b:Int):Int={// println(a+b) return a+b; }}

 

转载地址:http://ysnq.baihongyu.com/

你可能感兴趣的文章
压缩解压
查看>>
js try{}catch(){}finally{}语句
查看>>
PAT (Basic Level) Practice (中文)——1005 继续(3n+1)猜想 (25分)
查看>>
PAT (Basic Level) Practice (中文)——1011 A+B 和 C (15分)
查看>>
i711700K和r55600x差距大不大 i7 11700K和r5 5600x对比哪个好
查看>>
R3 PRO 3200G和r7 3700u 哪个好
查看>>
入手评测 联想小新Pro14和Air14Plus哪个好?区别对比
查看>>
程序人生:没有伞的孩子要学会奔跑
查看>>
Express Animate for mac(动画特效制作软件)
查看>>
macOS Big Sur系统中如何开启设置触控板三指拖拽功能?
查看>>
修复苹果Mac中的快速视频播放错误的方法
查看>>
苹果HomePod智能音箱怎么使用广播功能?
查看>>
Mac系统投屏到电视机的方法
查看>>
【Docker&ARM】ARM架构服务器上docker的安装
查看>>
【Tinyproxy】CentOS7.X http代理tinyproxy的安装配置与使用
查看>>
php--自定义错误处理函数的使用方法
查看>>
php--异常处理主动抛出异常的使用方法
查看>>
php--class static
查看>>
php--匿名函数的使用
查看>>
php--json_decode
查看>>