一、输入和输出
### --- 输入输出说明
~~~ 通过readLine 从控制台读取一行输入。
~~~ 如果要读取数字、Boolean或者字符,
~~~ 可以用readInt、readDouble、readByte、readShort、readLong、readFloat、readBoolean或者readChar。
### --- 输入输出编程语法
~~~ # printf 带有C语言风格的格式化字符串的 printf 函数
printf("Hello, %s! You are %d years old.", "Scala", 18)
### --- 编程代码
package yanqi.cn.part01
object ReadLineAndPrintDemo {
def main(args: Array[String]): Unit = {
print("请输入您的姓名:")
val name=scala.io.StdIn.readLine()
print("请输入您的年龄:")
val age=scala.io.StdIn.readInt()
println("您的姓名是:"+name+",年龄:"+age)
//printf是一个带有C语言风格的格式化字符串函数
printf("您的姓名是:%s,年龄:%d",name,age)
println()
println(s"您的姓名:$name,年龄:$age")
}
}
### --- 编译打印
D:\JAVA\jdk1.8.0_231\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=52015:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath D:\JAVA\jdk1.8.0_231\jre\lib\charsets.jar;D:\JAVA\jdk1.8.0_231\jre\lib\deploy.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\dnsns.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\jaccess.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\localedata.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\nashorn.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\sunec.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;D:\JAVA\jdk1.8.0_231\jre\lib\ext\zipfs.jar;D:\JAVA\jdk1.8.0_231\jre\lib\javaws.jar;D:\JAVA\jdk1.8.0_231\jre\lib\jce.jar;D:\JAVA\jdk1.8.0_231\jre\lib\jfr.jar;D:\JAVA\jdk1.8.0_231\jre\lib\jfxswt.jar;D:\JAVA\jdk1.8.0_231\jre\lib\jsse.jar;D:\JAVA\jdk1.8.0_231\jre\lib\management-agent.jar;D:\JAVA\jdk1.8.0_231\jre\lib\plugin.jar;D:\JAVA\jdk1.8.0_231\jre\lib\resources.jar;D:\JAVA\jdk1.8.0_231\jre\lib\rt.jar;E:\NO.Z.10000——javaproject\NO.Z.00002.Hadoop\ScalaPro\out\production\ScalaPro;D:\JAVA\scala-2.12.2\lib\scala-library.jar;D:\JAVA\scala-2.12.2\lib\scala-reflect.jar yanqi.cn.part01.ReadLineAndPrintDemo
请输入您的姓名:yanqi
请输入您的年龄:28
您的姓名是:yanqi,年龄:28
您的姓名是:yanqi,年龄:28
您的姓名:yanqi,年龄:28
Process finished with exit code 0