Import java.util.concurrent.timeunit; import java.util.date;import java.util.random;import java.util.*;p Ublic class wz{ public static void main (String[] args) throws exception{ int engishcount=0;int chinesecount=0;int digitcount=0;// string str = "China AADF 111 sa BBB zz sa phenanthrene";//string str = "China AADF 11"; string str = "China AADF 111 sa bb shaanxi Chongqing"; for (Int i=0;i<str.length (); i++) {char ch = Str.charat (i); if (ch>= ' 0 ' && ch<= ' 9 ') digitcount++; else if ((ch>= ' a ' && ch<= ' z ') | | (ch>= ' A ' && ch<= ' Z ')) {engishcount++;} else chinesecount++;} System.out.println ("chinesecount = " +chinesecount); System.out.println (" engishCount= " +ENGISHCOunt); System.out.println ("digitcount = " +digitcount);}
The result of the test is that the space is counted into the Chinese characters ....
Small Code Java character statistics