Menu
Question Index
...

What will be the output of the following program?

public class EasyPhoneDialing {

    public static void main(String[] args) {
        System.out.println("8500-MC-CALL" + "=" + convertToNumber("8500-MC-CALL"));
        System.out.println("HELLO-PAWAN" + "=" + convertToNumber("HELLO-PAWAN"));
        System.out.println("GODISGREAT" + "=" + convertToNumber("GODISGREAT"));
        System.out.println("SEASWORD04" + "=" + convertToNumber("SEASWORD04"));
    }

    public static String convertToNumber(String easyDialString) {
        String[] map = {"ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"};
        String result = "";
        for (char c : easyDialString.toCharArray()) {
            if (Character.isLetter(c)) {
                int i = 0;
                for (String entry : map) {
                    if (entry.contains(Character.toUpperCase(c) + "")) {
                        result += (i + 2);
                    }
                    i++;
                }
            } else {
                result += c;
            }
        }
        return result;
    }
}


8500-MC-CALL=8500-40-0033
HELLO-PAWAN=21334-50704
GODISGREAT=2412525106
SEASWORD04=5105745104
8500-MC-CALL=8500-62-2255
HELLO-PAWAN=43556-72926
GODISGREAT=4634747328
SEASWORD04=7327967304
8500-MC-CALL=622255
HELLO-PAWAN=4355672926
GODISGREAT=4634747328
SEASWORD04=73279673
Some other output or Compilation Error or Runtime Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App