Given a String. we have to print out the letter repetition
Sample input "aaaabbaac"
Sample output "4a2b2a1c"
public void continousWords(String input) {
String sample= input +" ";
String[] sampleList = sample.split("");
String temp = sampleList[0];
String result="";
int placeHolder=0;
for(int i=0;i<sampleList.length;i++){
if(temp.equalsIgnoreCase(sampleList[i])) {
placeHolder++;
}
else {
result = result+placeHolder+temp;
placeHolder =1;
temp = sampleList[i];
}
}
System.out.println(result);
}
Is there a better way to approach the problem