In the following problems do not use any mutable variables (i.e., variables decl
ID: 3887672 • Letter: I
Question
In the following problems do not use any mutable variables (i.e., variables declared with var) or any mutable predened types such as arrays, mutable sets, and so on. You may dene methods recursively this time. Do not use the if operator in Problems 1-4 below.
2. Write a Scala method concatAll (l: List[String]):String which, given any list l of strings, returns the concatenation of all the strings in l. For example, concatAll(List("un", "be", "liev", "a", "ble")) is ”unbelievable”.
Note that in Scala "" is the empty string and ++ is the inx concatenation operator for strings.
Explanation / Answer
object MyClass {
def concatAll(l: List[String]) = l.mkString("")
def main(args: Array[String]) {
print( concatAll(List("un", "be", "liev", "a", "ble")) );
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.