-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneWords.java
More file actions
56 lines (50 loc) · 1.79 KB
/
Copy pathPhoneWords.java
File metadata and controls
56 lines (50 loc) · 1.79 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class PhoneWords {
public static void main(String[] args){
System.out.println(phoneWords("443355555566604466690277733099966688"));
}
public static String phoneWords(String str) {
// 416666663105558822255
if(str.isEmpty()) return "";
else{
StringBuilder output = new StringBuilder();
char firstCharacter = str.charAt(0);
output.append(firstCharacter);
StringBuilder test = new StringBuilder(firstCharacter+"");
for(int i =1 ; i<str.length(); i++){
if(firstCharacter == str.charAt(i)){
test.append(str.charAt(i));
}
else{
output.append(validate(test));
test.setLength(0);
firstCharacter = str.charAt(i);
test.append(str.charAt(i));
}
}
output.append(validate(test));
return null;
}
}
public static StringBuilder validate(StringBuilder test){
char button = test.charAt(0);
StringBuilder result = new StringBuilder();
switch (button){
case '1' -> {
}
case '2' -> {
int counter = test.length();
if (counter%3>=3) result.append('c');
else if (counter%2>=2) result.append('b');
}
case '3' -> new StringBuilder("1");
case '4' -> new StringBuilder("1");
case '5' -> new StringBuilder("1");
case '6' -> new StringBuilder("1");
case '7' -> new StringBuilder("1");
case '8' -> new StringBuilder("1");
case '9' -> new StringBuilder("1");
case '0' -> new StringBuilder("1");
}
return new StringBuilder();
}
}