object StringDecoder { def main(args: Array[String]): Unit = { println("String Decoder") // Input: Encoded string val encodedString = "Hello%20World%21" // Example: URL-encoded string // Decode the string val decodedString = decode(encodedString, "UTF-8") // Output the result println(s"Encoded String: $encodedString") println(s"Decoded String: $decodedString") } def decode(encodedString: String, encoding: String): String = { try { val decoded = java.net.URLDecoder.decode(encodedString, encoding) decoded } catch { case e: Exception => println(s"Error decoding the string: ${e.getMessage}") throw e } } }import java.nio.charset.Charset object StringDecoder { def main(args: Array[String]): Unit = { // Input: Encoded string val encodedString = "Hello%20World%21" // Example: URL-encoded string // Specify the encoding used for decoding val encoding = "UTF-8" try { // Decode the string val decodedString = java.net.URLDecoder.decode(encodedString, encoding) // Output the decoded string println(s"Decoded String: $decodedString") } catch { case e: Exception => println(s"Error decoding the string: ${e.getMessage}") } } }