+ 1

Given a String containing numbers and uppercase characters (A-Z) , write Java methods that decompresses the String

Example : 2W3B 》》 input WWBBB 》》 output

5th Apr 2017, 3:35 PM
Ahmed Sameh
Ahmed Sameh - avatar
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);
5th Apr 2017, 7:44 PM
Rrestoring faith
Rrestoring faith - avatar