scala 身份证号码
根据身份证号码查询该持卡人的籍贯
object Test_身份证查询籍贯 {
def main(args: Array[String]): Unit = {
val code = "42005200210030051".substring(0,2)
println(code)
//判断42是哪个省的
//湖北
// if(code == "42"){
// println("42对应省份为:湖北")
// }else if(code =="33"){
// println("浙江")
// }else{
// println()
// }
val province = code match {
case "11" => "北京"
case "12" => "天津"
case "13" => "河北"
case "14" => "山西"
case "15" => "内蒙古"
case "21" => "辽宁"
case "22" => "吉林"
case "23" => "黑龙江"
case "31" => "上海"
case "32" => "上海"
case "33" => "浙江"
case "34" => "安徽"
case "35" => "福建"
case "36" => "江西"
case "37" => "山东"
case "41" => "河南"
case "42" => "湖北"
case "43" => "湖南"
case "44" => "广东"
case "45" => "广西"
case "46" => "海南"
case "50" => "重庆"
case "51" => "四川"
case "52" => "贵州"
case "53" => "云南"
case "54" => "西藏"
case "61" => "陕西"
case "62" => "甘肃"
case "63" => "青海"
case "64" => "宁夏"
case "65" => "新疆"
case "71" => "台湾"
case "81" => "香港"
case "82" => "澳门"
case "91" => "国外"
case "_" => "未知"
}
println(province)
}
}
根据1,2,3,4,5,6,7 --> 对应 的星期的英文
val code1=6
val day =code1 match {
case 1 => "monday"
case 2 => "tuesday"
case 3 => "wednesday"
case 4 => "thursday"
case 5 => "friday"
case 6 => "saturday"
case 7 => "sunday"
case _=>"该星期数不存在"
}
println(day)
val m1 =Map((1,"monday"),(2,"tuesday"),(3,"wednesday"),(4,"thursday"),(5,"friday"),(6,"saturday"),(7,"sunday"))
println(m1(30))
val t0 =(3)
val t1 =(2,3)
val t2 =(2,3,4)
//P220
//求长方形,梯形,正方形的面积
def patterTuple(x:Any) =x match {
case (a) =>println("正方形的面积")
case (a,b) =>println("长方形的面积")
case (a,b,c) =>println(s"梯形面积${a}")
case _ => println("未知")
}
patterTuple(t0)
patterTuple(t1)
patterTuple(t2)