java三种判断字母大小写的方法
2013-09-28 20:35
537 查看
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);
}
}
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笔试题---override与overload的区别
- Java运算符与java语句
- Java中equals和==的区别
- 马士兵java视频学习笔记第一章:Hello,World!
- eclipse中设定文档注释
- Activiti5安装指南-Myeclipse 9.0
- Struts2中文件上传的两种方式
- Struts2中文件上传的两种方式
- Java基础 之软引用、弱引用、虚引用
- java笔试题---如何跳出当前的多重嵌套循环
- struts2实现文件下载
- Tutorial: Getting Started with Spring Security
- 马士兵java视频学习笔记第一章:安装jdk
- java线程
- JAVA WEB入门级
- JDom解析和生成XML文档
- nyoj 4 ASCII码排序 java
- java动态代理(JDK和cglib)
- eclipse中一个项目,项目名前总是出现红色感叹号!
- java使用axis调用webservice时出现Connection reset by peer: socket write error的一种解决方法