Phoneword reader

Report a typo

Scally wants to transform phone numbers from phoneword format.

keypad of a pushbutton phone

She has run the program below. Complete this program, given that all conversion words will be 4 characters long.

Sample Input 1:

ring

Sample Output 1:

7464
Write a program in Scala 3
object Phoneword extends App {
val mapping = Map(
'0' -> 0,
'1' -> 1,
'a' -> 2, 'b' -> 2, 'c' -> 2,
'd' -> 3, 'e' -> 3, 'f' -> 3,
'g' -> 4, 'h' -> 4, 'i' -> 4,
'j' -> 5, 'k' -> 5, 'l' -> 5,
'm' -> 6, 'n' -> 6, 'o' -> 6,
???
't' -> 8, 'u' -> 8, 'v' -> 8,
'w' -> 9, 'x' -> 9, 'y' -> 9, 'z' -> 9
)
val chars = scala.io.StdIn.readLine().toCharArray

print(mapping(chars(0)))
???
print(mapping(chars(???)))
}
___

Create a free account to access the full topic