码迷,mamicode.com
首页 > 其他好文 > 详细

判断字母的大小写方法(3种)

时间:2015-10-06 19:28:50      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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);
}
 
}
 
//转载于清灵介质

 

判断字母的大小写方法(3种)

标签:

原文地址:http://www.cnblogs.com/aloney/p/4857516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!