mport scala.io.StdIn
object 随机职业 {
def main(args: Array[String]): Unit = {
println("请输入一个1~5之间的整数,预测您上上上上上辈子的职业:")
val num = StdIn.readInt()
val occupation = num match {
case 1 => "带刀侍卫"
case 2 => "宰相"
case 3 => "江湖郎中"
case 4 => "打铁匠"
case 5 => "店小二"
case _ => "公公"
}
println(s"您上上上上上辈子的职业是:$occupation")
}
}
scala模式匹配之案例
最新推荐文章于 2024-07-18 10:28:51 发布