您的位置:首页 > 编程语言 > Java开发

Java三种判断字母大小写的方法

2016-06-10 11:43 441 查看
public class AaNum {
public static void main(String[] args) {
String s = new String("12HMa&%$k#d_34H3aH");
int max = 0;
int min = 0;
int other = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
max++;
} else if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
min++;
} else
other++;
}
System.out.println("max:" + max + "\nmin:" + min + "\nother:" + other);
max = 0;
min = 0;
other = 0;
for (int i = 0; i < s.length(); i++) {
if (Character.isUpperCase(s.charAt(i)) == true) {
max++;
} else if (Character.isLowerCase(s.charAt(i)) == true) {
min++;
} else
other++;
}
System.out.println("max:" + max + "\nmin:" + min + "\nother:" + other);
max = 0;
min = 0;
other = 0;
String sL = "abcdefghijklmnopqrstuvwxyz";
String sU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < s.length(); i++) {
if (sL.indexOf(s.charAt(i)) != -1) {
max++;
} else if (sU.indexOf(s.charAt(i)) != -1) {
min++;
} else
other++;
}
System.out.println("max:" + max + "\nmin:" + min + "\nother:" + other);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java