Easy java solution with StringBuilder


#1
public String countAndSay(int A) {
        StringBuilder prev = new StringBuilder("1");
        StringBuilder next = new StringBuilder();

        int i = 0;
        int last = A-1;
        int count;
        while(i < last) { // For how many we need
            int j = 0;
            while(j < prev.length()) { // Get the previous string
                char ch = prev.charAt(j); // Get current character of previous string
                int l = j;
                count = 0;
                while ( l < prev.length() && ch == prev.charAt(l)) { // Repeat for this character and get its count
                    if(ch == prev.charAt(l)) {
                        count++;
                        l++;
                    }
                }
                j = l; // To get the next character
                
                next.append(count); // Add the count of character
                next.append(ch);    // Add the character
            }
            prev = next; // Set previous to new String we got now
            next = new StringBuilder(); 
            i++; // Repeat to get next string
        }
        return prev.toString();
    }