输入输出

35 阅读1分钟

2025.09.04

object helloworld {
  def main(args: Array[String]): Unit = {
    //获取用户的输入
    //io: input 输入, output 输出
    //scala.io.StdIn.readLine
    val input = scala.io.StdIn.readLine("请输入一些文本:")
    //用户输入完成,回车,内容就会保存到input这变量里
    
    //输出
    println("你输入的是:" + input)
  }

}

屏幕截图 2025-09-04 084233.png

object helloworld {
  def main(args: Array[String]): Unit = {
    //获取用户的输入
    //io: input 输入, output 输出
    //scala.io.StdIn.readLine
    val input = scala.io.StdIn.readLine("请输入一些文本:")
    //用户输入完成,回车,内容就会保存到input这变量里
    
    //输出
    println("你输入的是:" + input)
    print("请输入年龄:")
    val age = scala.io.StdIn.readLine()
    print("请输入身高:米")
    val height = scala.io.StdIn.readLine()
    println("你输入的是:" + age)
    println("你输入的是" + height)
  }

}

屏幕截图 2025-09-04 091419.png

println(s"$age 岁,$height 身高")//字符串插值

屏幕截图 2025-09-04 092443.png