Scala_1.控制台打印,变量定义,函数定义

Scala_1.控制台打印,变量定义,函数定义

package com.lius
import 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 =
      """
       <form id="daform">
       <p>Press belo',Joe</p>
       <input type="submit">
       </form>
      """

    println(html)
  }

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值