-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobilenum.java
More file actions
42 lines (37 loc) · 1.2 KB
/
mobilenum.java
File metadata and controls
42 lines (37 loc) · 1.2 KB
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
import java.util.*;
public class mobilenum {
static String printSequence(String arr[], String input)
{
String output = "";
// length of input string
int n = input.length();
for (int i = 0; i < n; i++) {
// Checking for space
if (input.charAt(i) == ' ')
output = output + "0";
else {
// Calculating index for each
// character
int position = input.charAt(i) - 'A';
output = output + arr[position];
}
}
// Output sequence
return output;
}
// Driver Code
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
// storing the sequence in array
System.out.println("Enter string in capital letter");
String input=sc.nextLine();
String str[]
= { "2", "22", "222", "3", "33", "333",
"4", "44", "444", "5", "55", "555",
"6", "66", "666", "7", "77", "777",
"7777", "8", "88", "888", "9", "99",
"999", "9999" };
System.out.println(printSequence(str, input));
}
}