On your phone keypad and old ones, the alphabets are mapped to digits as follows: ABC(2), DEF(3), GHI(4), JKL(5), MNO(6), PQRS(7), TUV(8), WXYZ(9). Write a program which prompts user for a String (case insensitive), and converts to a sequence of Keypad digits.
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String str = scan.next().toLowerCase();
for(int i = 0; i <= (str.length()-1); i++)
{
if(str.charAt(i) == 'A')
System.out.print("2");
else if(str.charAt(i) == 'B')
System.out.print("22");
else if(str.charAt(i) == 'C')
System.out.print("222");
else if(str.charAt(i) == 'D')
System.out.print("3");
else if(str.charAt(i) == 'E')
System.out.print("33");
else if(str.charAt(i) == 'F')
System.out.print("333");
else if(str.charAt(i) == 'G')
System.out.print("4");
else if(str.charAt(i) == 'H')
System.out.print("44");
else if(str.charAt(i) == 'I')
System.out.print("444");
else if(str.charAt(i) == 'J')
System.out.print("5");
else if(str.charAt(i) == 'K')
System.out.print("55");
else if(str.charAt(i) == 'L')
System.out.print("555");
else if(str.charAt(i) == 'M')
System.out.print("6");
else if(str.charAt(i) == 'N')
System.out.print("66");
else if(str.charAt(i) == 'O')
System.out.print("666");
else if(str.charAt(i) == 'P')
System.out.print("7");
else if(str.charAt(i) == 'Q')
System.out.print("77");
else if(str.charAt(i) == 'R')
System.out.print("777");
else if(str.charAt(i) == 'S')
System.out.print("7777");
else if(str.charAt(i) == 'T')
System.out.print("8");
else if(str.charAt(i) == 'U')
System.out.print("88");
else if(str.charAt(i) == 'V')
System.out.print("888");
else if(str.charAt(i) == 'W')
System.out.print("9");
else if(str.charAt(i) == 'X')
System.out.print("99");
else if(str.charAt(i) == 'Y')
System.out.print("999");
else if(str.charAt(i) == 'Z')
System.out.print("9999");
}
}
When I write a string, it's not giving me anything! Just blank. What seems to be the problem?