@@ -0,0 +1,1456 @@
+/**%0A *%09The count-and-say sequence is the sequence of integers beginning as follows:%0A *%091, 11, 21, 1211, 111221, ...%0A *%0A *%091 is read off as %22one 1%22 or 11.%0A *%0911 is read off as %22two 1s%22 or 21.%0A *%0921 is read off as %22one 2, then one 1%22 or 1211.%0A *%09Given an integer n, generate the nth sequence.%0A *%0A *%09Note: The sequence of integers will be represented as a string.%0A *%0A *%09Author: matao%0A *%0A */%0A%0Apublic class CountAndSay %7B%0A%09public static String countAndSay(int n) %7B%0A%09%09if(n %3C= 0) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09String oldString = %221%22;%0A%09%09if(n == 1) %7B%0A%09%09%09return oldString;%0A%09%09%7D%0A%09%09for(int i = 1; i %3C n; i++) %7B%0A%09%09%09oldString = generateNext(oldString);%0A%09%09%7D%0A%09%09return oldString;%0A    %7D%0A%0A    public static String generateNext(String s) %7B%0A    %09String result;%0A    %09int count = 1;%0A    %09char pre = s.charAt(0);%0A    %09StringBuilder sb = new StringBuilder();%0A    %09for (int i = 1; i %3C s.length(); i++) %7B%0A    %09%09if(s.charAt(i) == pre) %7B%0A    %09%09%09count++;%0A    %09%09%7D else %7B%0A    %09%09%09sb.append(count + String.valueOf(pre));%0A    %09%09%09pre = s.charAt(i);%0A    %09%09%09count = 1;%0A    %09%09%7D%0A    %09%7D%0A    %09sb.append(count + String.valueOf(pre));%0A    %09return sb.toString();%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09System.out.println(countAndSay(0));%0A    %09System.out.println(countAndSay(1));%0A    %09System.out.println(countAndSay(2));%0A    %09System.out.println(countAndSay(3));%0A    %09System.out.println(countAndSay(4));%0A    %09System.out.println(countAndSay(5));%0A    %09System.out.println(countAndSay(6));%0A    %7D%0A%7D

add Count And Say solution