import java.io.{File,PrintWriter}
import scala.io.Source
object Test06_FileI0 {
def main(args: Array[String]): Unit = {
Source.fromFile("E:/scalaStudy/Test").foreach(print)
val writer=new PrintWriter(new File("E:/scalaStudy/Intput.txt"))
writer.write("Hello,The apple is grape")
writer.close()
}
}
import scala.io.StdIn
object Test05_StdIn {
def main(args: Array[String]): Unit = {
print("请输入您的大名:")
val name:String=StdIn.readLine()
print("请输入您的芳龄:")
val age:Int=StdIn.readInt()
println(s"它的名字叫:${name},它的年龄是${age}岁,它还小少给他看点少儿不宜的.")
}
}
object Test04_String {
def main(args: Array[String]): Unit = {
val name:String="alice"
val age:Int=18
println(age+"岁前"+name+"在尚硅谷学习!")
println(name * 3)
printf("%d岁的%s在尚硅谷学习",age,name)
println()
println(s"${age}岁的人它的名字是${name}")
val num:Float=2.1234f
println(f"The num is ${num}%.2f")
var sql:String=s"""
|select *
|from
| student
|where
| name=${name}
|and
| age>${age}
|""".stripMargin
println(sql)
}
}
object Test03_Identifier {
def main(args: Array[String]): Unit = {
var hello:String=""
var hello123=""
val _abc=123
val -+/% ="hello"
println(-+/%)
val `if`="if"
print(`if`)
}
}
object Test02_Variable {
var alice=new Student("alice",20)
alice=new Student("Alice",19)
val bob=new Student("Bob",18)
bob.age=20
print(bob)
}
|