黑马程序员技术交流社区
标题:
输入一行字符,分别统计出其中英文字母、空格、数字和...
[打印本页]
作者:
javaee王虎
时间:
2016-7-22 01:03
标题:
输入一行字符,分别统计出其中英文字母、空格、数字和...
求想法以及代码
作者:
zjhjavaee
时间:
2016-7-22 11:18
String str1 = "adasfAAADFD 123&*";
int letter = 0;
int number = 0;
int space = 0;
int other=0;
for (int i = 0; i < str1.length(); i++) {
if (Character.isDigit(str1.charAt(i))) {
letter++;
}else if(Character.isLetter(str1.charAt(i))){
number++;
}else if (Character.isSpace(str1.charAt(i))) {
space++;
}
else{
other++;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2