AF
Home
Tag
Submit Notes
Ask Anything
Login
Subscribe Us
A
ny
F
orum
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.
Follow @anyforumin
corejava-programming: Mobile Key-Pad in Java
On a Mobile Key Pad the letters are mapped to the digits like following : ABC(2), DEF(3), GHI(4), JKL(5), MNO(6), PQRS(7), TUV(8), WXYZ(9) Write a program which will take a String as input and the output will be a sequence of digits according to the mentioned mapping.
Note: You can assume that the input will not contain more than 10 letters and all the letters will be in upper case.
Input Specification: Input will contain one line containing string in uppercase without spaces.
Output: Output should contain single line specifying the numbers corresponding to the characters in the string
Sample Input : JAVA
Sample Output: 5282
corejava x 353
programming x 168
Posted On :
2016-10-05 19:09:48.0
Akash Prasad
25
5
0
5
Answers
Check this code and Let me know if the test cases are satisfied or not.
------------------------------------------------
import java.util.Scanner;
public class MobileKeyPad
{
public static void main(String agrs[])
{
Scanner s=new Scanner(System.in);
String sample =s.nextLine();
//String cutString = sample.substring(0, 10);
//it takes only first first 10 letters to a string
char arraysample[] = sample.toCharArray();
int length = sample.length();
int count=0;
if(sample.length()<10)
{
for(int i = 0; i < length; i++)
{
char c = arraysample[i];
switch (c)
{
case ´A´:
case ´B´:
case ´C´:
count=2;
break;
case ´D´:
case ´E´:
case ´F´:
count=3;
break;
case ´G´:
case ´H´:
case ´I´:
count=4;
break;
case ´J´:
case ´K´:
case ´L´:
count=5;
break;
case ´M´:
case ´N´:
case ´O´:
count=6;
break;
case ´P´:
case ´Q´:
case ´R´:
case ´S´:
count=7;
break;
case ´T´:
case ´U´:
case ´V´:
count=8;
break;
case ´W´:
case ´X´:
case ´Y´:
case ´Z´:
count=9;
break;
default :
count=0;
break;
}
if(count==0)
{
System.out.println("Don´t use small letters...");
break;
}
else
System.out.print(count);
}
}
else{
System.out.println("You Have Entered More Than 10 Letter...TryAgain....");
}
}
}
Posted On :
2016-10-07 16:29:50
Satisfied :
8 Yes
7 No
Sudheer Kumar Javvadi
0
96
0
Reply This Thread
5
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in