Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String convertMaskedPhone(String phone) {
        StringBuilder phoneNumber = new StringBuilder(phone);
        for (int i = 0; i < phoneNumber.length(); i++) {
            switch (Character.toLowerCase(phoneNumber.charAt(i))) {
            case 'a':
            case 'b':
            case 'c':
                phoneNumber.setCharAt(i, '2');
                break;
            case 'd':
            case 'e':
            case 'f':
                phoneNumber.setCharAt(i, '3');
                break;
            case 'g':
            case 'h':
            case 'i':
                phoneNumber.setCharAt(i, '4');
                break;
            case 'j':
            case 'k':
            case 'l':
                phoneNumber.setCharAt(i, '5');
                break;
            case 'm':
            case 'n':
            case 'o':
                phoneNumber.setCharAt(i, '6');
                break;
            case 'p':
            case 'q':
            case 'r':
            case 's':
                phoneNumber.setCharAt(i, '7');
                break;
            case 't':
            case 'u':
            case 'v':
                phoneNumber.setCharAt(i, '8');
                break;
            case 'w':
            case 'x':
            case 'y':
            case 'z':
                phoneNumber.setCharAt(i, '9');
                break;
            case '+':
                phoneNumber.setCharAt(i, '0');
                break;
            }
        }
        return phoneNumber.toString();
    }
}