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

来源:互联网 发布:淘宝王子什么联系的 编辑:程序博客网 时间:2024/09/21 06:35
 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);
}

}
原创粉丝点击