import scala.collection.mutable.Map
def getMostRepeatedChar(str: String): Char = {
val charCounts = Map[Char, Int]()
var maxCount = 0
var maxChar = ' '
for (char <- str) {
val count = charCounts.getOrElse(char, 0) + 1
charCounts(char) = count
if (count > maxCount) {
maxCount = count
maxChar = char
}
}
maxChar
}
val str = "scalarustc++javascriptcphpc#";
val mostRepeatedChar = getMostRepeatedChar(str)
println(s"The most repeated character is: '$mostRepeatedChar'")
/*
run:
The most repeated character is: 'c'
*/