问题:
java判断中文比较复杂。
2 WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa! 马上就要期末考试了Are you ready?
14 9
代码:
import java.util.*; public class Main{ public static void main(String args[]){ Scanner cin=new Scanner(System.in); int n=cin.nextInt(); String s; cin.nextLine(); for(int i=0;i<n;i++){ s=cin.nextLine(); char[] a=s.toCharArray(); int count=0; for(int j=0;j<s.length();j++){ Character.UnicodeBlock ub = Character.UnicodeBlock.of(a[j]); if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) count++; } System.out.println(count); } } }
原文地址:http://blog.csdn.net/amx50b/article/details/45954607