1 package demo; 2 Import Java. util. break; 3/** 4 * count the numbers of English letters, spaces, numbers, and other characters in a string. 5 */6 public class statistics1 {7 public static void main (string [] ARGs) {8 int I; 9 int lettercount = 0; 10 int spacecount = 0; 11 int numbercount = 0; 12 INT othercount = 0; 13 14 // enter a string of 15 bytes in = new bytes (system. in); 16 system. out. println ("enter a string:"); 17 string STR = in. nextline (); 18 19 // string to character array 20 char [] CH = Str. tochararray (); 21 for (I = 0; I <Str. length (); I ++) {22 if (character. isletter (CH [I]) {23 lettercount ++; 24} else if (character. isspacechar (CH [I]) {25 spacecount ++; 26} else if (character. isdigit (CH [I]) {27 numbercount ++; 28} 29 else {30 othercount ++; 31} 32} 33 34 system. out. println ("the number of characters is:" + lettercount); 35 system. out. println ("number of spaces:" + spacecount); 36 system. out. println ("number:" + numbercount); 37 system. out. println ("other characters:" + othercount); 38} 39}