Language: Java

import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);
        final char[][] keymap =
                { null,
                  { ''', ',', '.', '!', '?' },
                  { 'a', 'b', 'c', 'A', 'B', 'C' },
                  { 'd', 'e', 'f', 'D', 'E', 'F' },
                  { 'g', 'h', 'i', 'G', 'H', 'I' },
                  { 'j', 'k', 'l', 'J', 'K', 'L' },
                  { 'm', 'n', 'o', 'M', 'N', 'O' },
                  { 'p', 'q', 'r', 's',  'P', 'Q', 'R', 'S' },
                  { 't', 'u', 'v', 'T', 'U', 'V' },
                  { 'w', 'x', 'y', 'z', 'W', 'X', 'Y' , 'Z' }
                 };
        while (scanner.hasNext()) {
            final char[] line = scanner.next().toCharArray();
            int index = 0;
            while (index != line.length) {
                final char digit = line[index];
                int counter = 1;
                while (++index < line.length && line[index] == digit) {
                    counter++;
                }
                if (keymap[digit - '0'] == null) {
                    for (int i = 1; i < counter; i++) {
                        System.out.print(' ');
                    }
                } else {
                    final int length = keymap[digit - '0'].length;
                    System.out.print(keymap[digit - '0'][(counter - 1) % length]);
                }
            }
            System.out.println();
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Compiler output:
Main.java:8: error: empty character literal
                  { ''', ',', '.', '!', '?' },
                    ^
Main.java:8: error: unclosed character literal
                  { ''', ',', '.', '!', '?' },
                      ^
Main.java:8: error: illegal start of type
                  { ''', ',', '.', '!', '?' },
                                             ^
Main.java:8: error: <identifier> expected
                  { ''', ',', '.', '!', '?' },
                                              ^
Main.java:9: error: not a statement
                  { 'a', 'b', 'c', 'A', 'B', 'C' },
                    ^
Main.java:9: error: ';' expected
                  { 'a', 'b', 'c', 'A', 'B', 'C' },
                       ^
Main.java:9: error: illegal start of type
                  { 'a', 'b', 'c', 'A', 'B', 'C' },
                                                  ^
Main.java:9: error: <identifier> expected
                  { 'a', 'b', 'c', 'A', 'B', 'C' },
                                                   ^
Main.java:10: error: not a statement
                  { 'd', 'e', 'f', 'D', 'E', 'F' },
                    ^
Main.java:10: error: ';' expected
                  { 'd', 'e', 'f', 'D', 'E', 'F' },
                       ^
Main.java:10: error: illegal start of type
                  { 'd', 'e', 'f', 'D', 'E', 'F' },
                                                  ^
Main.java:10: error: <identifier> expected
                  { 'd', 'e', 'f', 'D', 'E', 'F' },
                                                   ^
Main.java:11: error: not a statement
                  { 'g', 'h', 'i', 'G', 'H', 'I' },
                    ^
Main.java:11: error: ';' expected
                  { 'g', 'h', 'i', 'G', 'H', 'I' },
                       ^
Main.java:11: error: illegal start of type
                  { 'g', 'h', 'i', 'G', 'H', 'I' },
                                                  ^
Main.java:11: error: <identifier> expected
                  { 'g', 'h', 'i', 'G', 'H', 'I' },
                                                   ^
Main.java:12: error: not a statement
                  { 'j', 'k', 'l', 'J', 'K', 'L' },
                    ^
Main.java:12: error: ';' expected
                  { 'j', 'k', 'l', 'J', 'K', 'L' },
                       ^
Main.java:12: error: illegal start of type
                  { 'j', 'k', 'l', 'J', 'K', 'L' },
                                                  ^
Main.java:12: error: <identifier> expected
                  { 'j', 'k', 'l', 'J', 'K', 'L' },
                                                   ^
Main.java:13: error: not a statement
                  { 'm', 'n', 'o', 'M', 'N', 'O' },
                    ^
Main.java:13: error: ';' expected
                  { 'm', 'n', 'o', 'M', 'N', 'O' },
                       ^
Main.java:13: error: illegal start of type
                  { 'm', 'n', 'o', 'M', 'N', 'O' },
                                                  ^
Main.java:13: error: <identifier> expected
                  { 'm', 'n', 'o', 'M', 'N', 'O' },
                                                   ^
Main.java:14: error: not a statement
                  { 'p', 'q', 'r', 's',  'P', 'Q', 'R', 'S' },
                    ^
Main.java:14: error: ';' expected
                  { 'p', 'q', 'r', 's',  'P', 'Q', 'R', 'S' },
                       ^
Main.java:14: error: illegal start of type
                  { 'p', 'q', 'r', 's',  'P', 'Q', 'R', 'S' },
                                                             ^
Main.java:14: error: <identifier> expected
                  { 'p', 'q', 'r', 's',  'P', 'Q', 'R', 'S' },
                                                              ^
Main.java:15: error: not a statement
                  { 't', 'u', 'v', 'T', 'U', 'V' },
                    ^
Main.java:15: error: ';' expected
                  { 't', 'u', 'v', 'T', 'U', 'V' },
                       ^
Main.java:15: error: illegal start of type
                  { 't', 'u', 'v', 'T', 'U', 'V' },
                                                  ^
Main.java:15: error: <identifier> expected
                  { 't', 'u', 'v', 'T', 'U', 'V' },
                                                   ^
Main.java:16: error: not a statement
                  { 'w', 'x', 'y', 'z', 'W', 'X', 'Y' , 'Z' }
                    ^
Main.java:16: error: ';' expected
                  { 'w', 'x', 'y', 'z', 'W', 'X', 'Y' , 'Z' }
                       ^
Main.java:18: error: class, interface, enum, or record expected
        while (scanner.hasNext()) {
        ^
Main.java:19: error: unnamed classes are a preview feature and are disabled by default.
            final char[] line = scanner.next().toCharArray();
                  ^
  (use --enable-preview to enable unnamed classes)
Main.java:21: error: class, interface, enum, or record expected
            while (index != line.length) {
            ^
Main.java:24: error: class, interface, enum, or record expected
                while (++index < line.length && line[index] == digit) {
                ^
Main.java:26: error: class, interface, enum, or record expected
                }
                ^
Main.java:28: error: class, interface, enum, or record expected
                    for (int i = 1; i < counter; i++) {
                                    ^
Main.java:28: error: class, interface, enum, or record expected
                    for (int i = 1; i < counter; i++) {
                                                 ^
Main.java:30: error: class, interface, enum, or record expected
                    }
                    ^
Main.java:33: error: class, interface, enum, or record expected
                    System.out.print(keymap[digit - '0'][(counter - 1) % length]);
                    ^
Main.java:34: error: class, interface, enum, or record expected
                }
                ^
Main.java:37: error: class, interface, enum, or record expected
        }
        ^
Main.java:43: error: class, interface, enum, or record expected
}
^
46 errors