+ 1
Given a String containing numbers and uppercase characters (A-Z) , write Java methods that decompresses the String
Example : 2W3B 》》 input WWBBB 》》 output
1 Answer
+ 4
So this assumes the letters come before the words, and that numbers are 0 <= x <= 9.
If you want me to make a more reliable version let me know, just on android. :3.
String word = "EX2A3MPLE";
String output = "";
int num = 0;
for(int i = 0; i < word.length(); i++){
try{
num = Integer.parseInt(String.valueOf(word.charAt(i)));
while(num-- > 1){
output += word.charAt(i+1);
}
}catch(Exception e){
output += word.charAt(i);
}
}
System.out.println(output);