N
N
Nikolaanastasiia2020-12-25 21:24:47
Java
Nikolaanastasiia, 2020-12-25 21:24:47

How to change the output?

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Task2 {
    public static void main(String[] args) {
        String text = "ZAAABBCCDDDD";
        Matcher m = Pattern.compile("(.)\\1+").matcher(text);
        while (m.find()) {
            String sub = m.group();
            System.out.println(sub + sub.length ());
        }
    }
}


For example, there is a string "AAABCCDDDD", I need it to come out "A3BC2D4", I also get all the letters, please tell me how to fix it?5fe62e4463f00680854859.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lyoshik, 2020-12-25
@Nikolaanastasiia

System.out.print(sub.substring(0, 1) + sub.length());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question