直接匹配

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int n = str.length();
        char[] c = str.toCharArray();
        for(int i = 0; i<n; i++){
            if(c[i]>='a' && c[i]<='c'){
                c[i] = '2';
            }else if(c[i]>='d' && c[i]<='f'){
                c[i] = '3';
            }else if(c[i]>='g' && c[i]<='i'){
                c[i] = '4';
            }else if(c[i]>='j' && c[i]<='l'){
                c[i] = '5';
            }else if(c[i]>='m' && c[i]<='o'){
                c[i] = '6';
            }else if(c[i]>='p' && c[i]<='s'){
                c[i] = '7';
            }else if(c[i]>='t' && c[i]<='v'){
                c[i] = '8';
            }else if(c[i]>='w' && c[i]<='z'){
                c[i] = '9';
            }else if(c[i]>='A' && c[i]<='Z'){
                int temp = c[i]+33;
                temp = temp>122?97:temp;
                c[i] = (char)temp;
            }
        }
        System.out.println(str.copyValueOf(c));
    }
}