5.2.1.2 for
遍历字符串中的字符
正常写法:
package com.atguigu.day02
object ForDemo3 {
def main(args: Array[String]): Unit = {
val s: String = "abcdef"
for (i <- 0 until s.length) {
print(s(i) + " ")
}
}
}
简洁写法:
package com.atguigu.day02
object ForDemo3 {
def main(args: Array[String]): Unit = {
val s: String = "abcdef"
for(c <- s){
print(c + " ")
}
}
}