Scally started a program that prints the type of the file by the extension of the name. Finish the program below. In case the program doesn't have any information about the extension, set the type to unknown.
Strings
File type checker
Report a typo
Sample Input 1:
a.txtSample Output 1:
File a.txt type is plain textWrite a program in Scala 3
object FileTypePrinter extends App {
val extensions = Map(
"txt" -> "plain text",
"scala" -> "Scala source code",
"bin" -> "binary data"
)
val file = scala.io.StdIn.readLine()
val extension = file.reverse.takeWhile(_ != '.').reverse.toLowerCase
println(s"File ??? type is ${extensions.getOrElse(extension, "???")}")
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.