import scala.util.control.Breaks.{break, breakable}
object work1 {
def main(args: Array[String]): Unit = {
breakable {
while (true) {
print("请输入要判断的年份(输入0就结束判断) : ")
val year = scala.io.StdIn.readInt()
if (year == 0) {
break
}
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
println(s"${year} 是闰年")
} else {
println(s"${year} 不是闰年")
}
}
}
}
}
object work2 {
def main(args: Array[String]): Unit = {
val stu3 = new Student("小明")
stu3.sayHi()
class Student(var name: String, var age: Int) {
println("构造函数被调用...")
def sayHi(): Unit = {
println(s"我是${name},我今年${age}")
}
def this() = {
this("无名氏", 0)
println("辅助构造函数1被调用...")
}
def this(name: String) = {
this(name, 0)
println("辅助构造函数2被调用...")
}
}
}
}