package com.fuxi.zji
object Ten3 {
def main(args: Array[String]): Unit = {
val words="""Scala combines object-oriented and functional programming in one concise, high-level language. Scala's static types help avoid bugs in complex applications, and its JVM and JavaScript runtimes let you build high-performance systems with easy access to huge ecosystems of libraries."""
val wordCounMap = scala.collection.mutable.Map[String,Int]()
def putword(word:String): Unit = {
if(!wordCounMap.contains(word))
wordCounMap.put(word,1)
else {
val acc = wordCounMap.getOrElse(word,0) //.getOrElse
wordCounMap.put(word,acc+1)
println(acc)
}
}
words.split(" ").foreach(word=>putword(word))
println(wordCounMap)
wordCounMap.foreach(kv=>println(kv._1,kv._2))
}
}
06-16
370
02-05
1486