AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
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 ?.



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 336
programming x 153
Posted On : 2016-10-05 19:09:48.0
profile Akash Prasad - anyforum.in Akash Prasad
2550
up-rate
5
down-rate

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 : 2 Yes  0 No
profile sudheerkumar Javvadi - anyforum.in sudheerkumar Javvadi
0970
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in