Print Consecutive Occurrences of Each Character in String Java

Posted on

Problem Statement: Write a program to print consecutive occurrences of each character in a given string.

Test case 1:
Input : affffssdaaag
Output: a1f4s2d1a3g1

Test case 2:
Input: affffssdaaa
Output: a1f4s2d1a3

Test case 3:
Input: aaa
Output: a3

We suggest you think about a solution before reading further…

Solution:

Lets see an example to understand how this can be achieved.

Output

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.