Q:

Write a Scala program to replace a specified character with another character

0

Write a Scala program to replace a specified character with another character.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_String {
  def main(args: Array[String]): Unit = {
    val str = "The quick brown fox jumps over the lazy dog.";

    // Replace all the 'd' characters with 'f' characters.
    val new_str = str.replace('d', 'f');
    // Display the strings for comparison.
    println("Original string: " + str);
    println("New String: " + new_str);
  }
}
Sample Output:
Original string: The quick brown fox jumps over the lazy dog.
New String: The quick brown fox jumps over the lazy fog.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now