Topics Index

Easy Phone Dialing

If you need explanation Read this topic

If you need Answer Take test on this topic

Easy Phone Dialing
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);
            } else {
                result += c;
        return result;

A. 8500-MC-CALL=8500-40-0033
B. 8500-MC-CALL=8500-62-2255
C. 8500-MC-CALL=622255
D. Some other output or Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B:..We are taking string n traveling throug it..if it digit we are adding to result else if it is char than we are serachng string string in map which contains this letter..while searchng we increasing i value..wen we found that char in a particular string we are adding I+2 n adding that value 2 result...

Posted by Uday Kumar    2014-05-29 09:11:44

ans b. 0 based string arr,convrtnum func each char 1st checkd if it is numbr or symbl thn directly prints tat nums .if its alphabt then indx value is takn from string arr and 2 is added.

Posted by Maheshwari Natarajan    2014-05-29 09:52:29

Congratulations Uday Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-30 06:00:53

© meritcampus 2019

All Rights Reserved.

Open In App