Continuous Occurrence of Duplicate Character Count Print in given String
SOURCE : DuplicateCharacterCountPrint.javapublic 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()); } } INPUTString s = "AABCCW";OUTPUT
A2B1C2W1

0 comments :
Post a Comment