-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetNumber.java
More file actions
55 lines (55 loc) · 923 Bytes
/
GetNumber.java
File metadata and controls
55 lines (55 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.Scanner;
public class GetNumber{
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
System.out.print("Enter a String: ");
String s1= input.next();
//
for (int i=0;i<s1.length();i++) {
char c=s1.charAt(i);
if (Character.isLetter(c)== true) {
c=Character.toUpperCase(c);
int x= getNumber(c);
System.out.print(x);
}
else {
System.out.print(c);
}
}
}
public static int getNumber(char uppercaseLetter){
switch (uppercaseLetter) {
case'A':
case'B':
case'C':
return 2;
case'D':
case'E':
case'F':
return 3;
case'G':
case'H':
case'I':
return 4;
case'J':
case'K':
case'L':
return 5;
case'M':
case'N':
case'O':
return 6;
case'P':
case'Q':
case'R':
case'S':
return 7;
case'T':
case'U':
case'V':
return 8;
default:
return 9;
}
}
}