标签:大写 ++ nbsp 字母 abc [] int str images
os :windows7 x64
jdk:jdk-8u131-windows-x64
ide:Eclipse Oxygen Release (4.7.0)
code:
package jizuiku.t01;
public class Demo00 {
public static void main(String[] args) {
String str = "abc012345ABCD!@#$";
int countOfDigit = 0;
int countOfLower = 0;
int countOfUpper = 0;
int countOfOther = 0;
for (int i = 0, stringLength = str.length(); i < stringLength; ++i) {
if (Character.isDigit(str.charAt(i))) {
++countOfDigit;//数字
} else if (Character.isLowerCase(str.charAt(i))) {
++countOfLower;//小写
} else if (Character.isUpperCase(str.charAt(i))) {
++countOfUpper;//大写
} else {
++countOfOther;//三种之外的类型
}
}
System.out.println("countOfDigit:"+countOfDigit);
System.out.println("countOfLower:"+countOfLower);
System.out.println("countOfUpper:"+countOfUpper);
System.out.println("countOfOther:"+countOfOther);
}
}
result:
Java优秀,值得学习。
学习资源:API手册+Java源码。
JavaSE8基础 Character.isXXX 判断一个字符是 数字 小写字母 大写字母
标签:大写 ++ nbsp 字母 abc [] int str images
原文地址:http://www.cnblogs.com/jizuiku/p/7468909.html