Scala学习笔记-07-模式匹配 - match case语句
case中的通配符 _ 相当于java中的default分支 match结构中不需要break语句来跳出判断,scala会从前往后匹配,一旦配到一个分支即停止 匹配字符: import scala.io.StdIn._ println("Please input the score Level: ") val grade = readChar() grade match{ case 'A' => println("85-100") case 'B' => println("70-84") case 'C' => println("60-69") case 'D' => println("< 60") case _ => println("error input !") } 匹配字符串 import scala.io.StdIn._ val country = readLine("please input your country: ") country match { case "中国" => println("you are from China") case "美国" => println("youa are from USA") case "日本" => println("you are from Japan") case _ => println("country