Easy to understand Java Solution using StringBuilder


#1
public class Solution {
    public String countAndSay(int A) {

        String output = "1";

        for (int i = 1; i < A ; i++) {
            StringBuilder temp = new StringBuilder();
            Character previousChar = output.charAt(0);
            int count = 1;
            for (int j = 1; j < output.length(); j++) {
                if (output.charAt(j) == output.charAt(j-1)){
                    count++;
                } else {
                    temp.append(String.valueOf(count));
                    temp.append(String.valueOf(previousChar));
                    previousChar = output.charAt(j);
                    count = 1;
                }
            }
            temp.append(String.valueOf(count));
            temp.append(String.valueOf(previousChar));
            output = temp.toString();
        }
        return output;
    }
}