Continuous Occurrence of Duplicate Character Count Print in given String

Continuous Occurrence of Duplicate Character Count Print in given String
SOURCE : DuplicateCharacterCountPrint.java



public class DuplicateCharacterCountPrint {

/**
* @param args
*/
public static void main(String[] args) {

int count = 0;
String s = "AABCCW";
StringBuilder sb = new StringBuilder();
char[] c = s.toCharArray();
char temp = c[0];
for(int i =0;i
if(temp==c[i]){
count ++;
}
else{
sb.append(temp);
sb.append(count);
temp=c[i];
count=1;
}

}
sb.append(temp);
sb.append(count);
System.out.println(sb.toString());
}


}


INPUT

String s = "AABCCW";



OUTPUT

A2B1C2W1






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment