1
2
3scala
def incrementNumber(s: String): String = {
s.map(_.asDigit + 1).mkString
}
val s = "123456"
println(incrementNumber(s)) // 输出 "234567"
解释:使用map方法将字符串中的每个字符转换成数字并加1,然后使用mkString方法将数字转换成字符串并拼接成一个新的字符串。
简单方法:
yield方法:
scala中 yield_yield scala_数据的星辰大海的博客-CSDN博客
true判定为北京身份证号。
3
---
Java,格式:
println(name+" is "+ age +" years old and weights is "+ weights +" kg ")
---scala格式:
println(s"name is $name,$age, years old and weights is $weights kg ")
println(f"name is $name,$age, years old and weights is $weights kg ")
println(raw"name is $name,$age, years old and weights is $weights kg ")
---
val input="hadoop01"
val hostslist="host01.host02.hadoop01.hadoop010"
val hosts=hostslist.split(",")
val hostnames=for(host<-hosts if (input.toUpperCase==host.toUpperCase)) yield host
if(hostnames.length>0) println(s"i find $input") else println(s"i unfind $input ")