/** * Generates a string containing all Chinese characters "one" word begins "\4e00 to 9FA5 * idea: * 1. Since it is all that contains, it is definitely from one character to another character of all characters * 2. Because each string object creates a different one, it will open up empty , avoid wasting memory, with StringBuilder stitching better * 3. Because it is the output of all stitching problems, so with the loop * 4. In order to avoid too many rows to display, 50 a newline display, so a counter * * Step * 1 is required. Loop variable initialization, where the loop variable should is the character C (\u4e00), * in the constant addition of 1 C + +, loop to the last 1 characters end C<=\U9FA5 * 2. Because there is a counter I, so stitching a character, should add a count of i++ * 3. Loop the body, establish the StringBuilder object. * Each loop stitching Sb.append (c) * 4. Wait I to 50, just sb.append ("\ n") * Note: Counter starts from 1, otherwise the first word, i%50 0 modulo 50, the result is 0, will wrap * Output statement on the outermost, direct output SB object. */
public class StringDemo3 { static void main (string[] args) {int i=1; StringBuilder sb = new StringBuilder (); for (char c= ' \u4e00 '; c<= ' \ U9fa5 '; C++,i++) {Sb.append (c); if (i%50 ==0) {Sb.append ( " \ n "); }} System.out.print (Sb.tostring ()); }}
View Code
Generate a string containing all Chinese characters "one" word start "\4e00 to 9fa5