如题,已完成了部分,不知道如何找出单词和汉字的个数?public class t6{public static void main(String[] args){String str="司”,,面试,t5.java";
int letters=0;
int numbers=0;
int chinese=0;
int ch_punctuation=0;
int words=0;
int punctuation=0;char c;
for(int i=0;i<str.length();i++){
c=str.charAt(i);
if(Character.isLetter(c)){
letters++;}else if(Character.isDigit(c)){
numbers++;}else if((int)c>127){
ch_punctuation++;}else if(Character.isWhitespace(c)){
continue;}else{punctuation++;
}}
System.out.println("letter:"+letters+"; numbers:"+numbers+"; 全角标点:"+ch_punctuation+"; chinese:"+chinese+" words:"+words+"; 英文标点:"+punctuation+"; length:"+str.length());}
}
int letters=0;
int numbers=0;
int chinese=0;
int ch_punctuation=0;
int words=0;
int punctuation=0;char c;
for(int i=0;i<str.length();i++){
c=str.charAt(i);
if(Character.isLetter(c)){
letters++;}else if(Character.isDigit(c)){
numbers++;}else if((int)c>127){
ch_punctuation++;}else if(Character.isWhitespace(c)){
continue;}else{punctuation++;
}}
System.out.println("letter:"+letters+"; numbers:"+numbers+"; 全角标点:"+ch_punctuation+"; chinese:"+chinese+" words:"+words+"; 英文标点:"+punctuation+"; length:"+str.length());}
}
解决方案 »
- 不求包养但求解析???????????
- 把BufferedReader里存的email对比 请大家帮忙
- ibm R60e的驱动如何安装
- 请大家进来看看,谢谢了,我真的很急,谢谢!!帮帮忙
- 有没有把sqlj翻译成用jdbc和sql的java程序的工具呢?
- byte[7]数组,内容为1,2,...7,转换为String,String显示为"1234567"怎么转换
- 怎样将JTable转化为JList
- 请问像xxxxxFactory这样的方法是什么东西? 有什么用?
- 能不能在applet中submit一个html页面。
- java 对象流的一些问题
- [100分]HeXuZhOnG(BT,思维中的战斗机) 和jFresH_MaN(十一月的萧邦-夜曲) ( 领分
- 请教一个读文件中字符串的问题
int i=0,j=0,k=0;
Pattern p = Pattern.compile("[\u4E00-\u9FA5]+");
Matcher m = p.matcher(str);
while(m.find())
i++;
p = Pattern.compile("\\w+");
m = p.matcher(str);
while(m.find())
j++;
p = Pattern.compile("[,\\.;:'\",。、?;:’”]");
m = p.matcher(str);
while(m.find())
k++;
System.out.println(i+"\t"+j+"\t"+k);
匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'。