Skip to content

Commit 9f2afe1

Browse files
committed
added convert to mobile sequence and Reverse Words
1 parent 705940d commit 9f2afe1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Strings/ConvertToMobileSequence.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Strings;
2+
3+
public class ConvertToMobileSequence {
4+
5+
String printSequence(String S)
6+
{
7+
// code here
8+
String[] nums = { "2", "22", "222", "3", "33", "333", "4", "44", "444", "5", "55", "555",
9+
"6", "66", "666", "7", "77", "777","7777", "8", "88", "888", "9", "99", "999", "9999" };
10+
11+
String ans = "";
12+
for(int i=0; i<S.length(); i++){
13+
if(S.charAt(i)==' '){
14+
ans += 0;
15+
}else{
16+
int j = S.charAt(i) - 'A';
17+
ans += nums[j];
18+
}
19+
}
20+
return ans;
21+
}
22+
public static void main(String[] args) {
23+
// take user input accordingly
24+
}
25+
}

Strings/ReverseWords.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package Strings;
2+
3+
import java.util.Stack;
4+
5+
public class ReverseWords {
6+
public static String reverseWords(String S)
7+
{
8+
// code here
9+
Stack<String> st = new Stack<>();
10+
11+
for(String word : S.split("\\.")){
12+
st.push(word);
13+
}
14+
15+
String s ="";
16+
while(!st.isEmpty()){
17+
s += st.pop();
18+
if(!st.isEmpty()){
19+
s+=".";
20+
}
21+
}
22+
return s;
23+
}
24+
public static void main(String[] args) {
25+
// take inputs accordingly
26+
}
27+
}

0 commit comments

Comments
 (0)