abccclesonnnnnnnnnnnnnnnnnnnn).I do it this way:String a = "abbc2kd3ijkl40ggg2H5uu";String s = a + "*";String numS = "";int cnt = 0;for (int i = 0; i < s.length(); i++) {char ch = s.charAt(i);if (Character.isDigit(ch)) {numS = numS + ch;cnt++;} else {cnt++;try {for (int j = 0; j < Integer.parseInt(numS); j++) {System.out.print(s.charAt(i - cnt));}if (i != s.length() - 1 && !Character.isDigit(s.charAt(i + 1))) {System.out.print(s.charAt(i)); }}..." />

Java - task with characters

It is necessary to repeat the character, as many times as the number behind it. They are single-digit, two-digit, three-digit and so on numbers (ex. "abc3leson11" to become-> abccclesonnnnnnnnnnnnnnnnnnnn).

I do it this way:

String a = "abbc2kd3ijkl40ggg2H5uu";

String s = a + "*";

String numS = "";

int cnt = 0;

for (int i = 0; i < s.length(); i++) {

char ch = s.charAt(i);

if (Character.isDigit(ch)) {

numS = numS + ch;

cnt++;

} else {

cnt++;

try {

for (int j = 0; j < Integer.parseInt(numS); j++) {

System.out.print(s.charAt(i - cnt));

}

if (i != s.length() - 1 && !Character.isDigit(s.charAt(i + 1))) {

System.out.print(s.charAt(i));

}

}...

Read More »

By: StackOverFlow - Friday, 20 July

Related Posts