
/**
 * The count-and-say sequence is the sequence of integers beginning as follows:
   1, 11, 21, 1211, 111221, ...

 * 1 is read off as "one 1" or 11.
 * 11 is read off as "two 1s" or 21.
 * 21 is read off as "one 2, then one 1" or 1211.
 * Given an integer n, generate the nth sequence.

 * Note: The sequence of integers will be represented as a string.
 * Note: brute way: loop string
 * @author chenshuna
 *
 */

public class countAndSay {
    public static String countAndSay(int n) {
        String restult = "1";
        for(int i=1;i<n;i++){
            restult = countAndSayArray(restult);
        }
        return restult;
    }
     public static String countAndSayArray(String cas) {
         int n = cas.length();
         int count = 1;
         int point = 0;
         StringBuilder res = new StringBuilder();
         while(point < n){
             while((point+count) < n && cas.charAt(point) == cas.charAt(point+count)){
                 count++;
             }
             res.append(count + "");
             res.append(cas.charAt(point) + "");
             point = point + count;
             count = 1;
         }
         
         return res.toString();
         
     }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.print(countAndSay(4));
	}

}

@@ -1132,26 +1132,16 @@
       %7D%0A
-         %0A
         
@@ -1173,22 +1173,15 @@
     
-    
+%7D
 %0A     
-%7D%0A%0A%09
 publ
@@ -1217,17 +1217,16 @@
 args) %7B%0A
-%09
 %09// TODO
@@ -1253,17 +1253,16 @@
 od stub%0A
-%09
 %09System.
@@ -1288,14 +1288,18 @@
 ay(4));%0A
-%09
+     
 %7D%0A%0A%7D%0A

Update CountAndSay_38.java