字符串处理练习
2011-06-30 15:29
141 查看
public class CountChar { private static int lowerCount = 0, upperCount = 0, otherCount = 0; public static void main(String[] args) { String str = new String("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789~!@#$%^&*()_+-=`|'"); useCharAt(str); useIndexOf(str); useIsLowerOrUpper(str); } private static void useCharAt(String str) { char c; lowerCount = 0; upperCount = 0; otherCount = 0; for (int i=0; i<str.length(); i++) { c = str.charAt(i); if (c >= 'a' && c <= 'z') { lowerCount ++; } else if (c >= 'A' && c <= 'Z') { upperCount ++; } else { otherCount ++; } } System.out.println("lowerCount:" + lowerCount + " upperCount:" + upperCount + " otherCount:" + otherCount); } private static void useIndexOf(String str) { char c; lowerCount = 0; upperCount = 0; otherCount = 0; String lowerStr = "abcdefghijklmnopqrstuvwxyz"; String upperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (int i=0; i<str.length(); i++) { c = str.charAt(i); if (lowerStr.indexOf(c) != -1) { lowerCount ++; } else if (upperStr.indexOf(c) != -1) { upperCount ++; } else { otherCount ++; } } System.out.println("lowerCount:" + lowerCount + " upperCount:" + upperCount + " otherCount:" + otherCount); } private static void useIsLowerOrUpper(String str) { char c; lowerCount = 0; upperCount = 0; otherCount = 0; for (int i=0; i<str.length(); i++) { c = str.charAt(i); if (Character.isLowerCase(c)) { lowerCount ++; } else if (Character.isUpperCase(c)) { upperCount ++; } else { otherCount ++; } } System.out.println("lowerCount:" + lowerCount + " upperCount:" + upperCount + " otherCount:" + otherCount); } }
相关文章推荐
- 安卓小日记练习(11)listview的动态更新和android的字符串处理
- json 字符串传到action之后的处理,遍历. 练习代码片
- STL练习之字符串的处理
- GPS数据处理——字符串编程练习(C语言)
- HDU 1870.愚人节的礼物【字符串处理】【思维练习】【8月2】
- 练习1-23:编写一个删除C语言程序中所有的注释语句。要正确处理带引号的字符串与字符常量。在C语言程序中,注释不允许嵌套
- 代码练习 简单文件读写 字符串 数组的处理 list Dictionary
- C# 实例练习——字符串处理(第一天)
- 蓝桥杯 基础练习 十六进制转八进制 【字符串处理】
- Javascript - 字符串,数组处理练习
- HDU 5414 CRB and String(字符串处理)——多校练习10
- 练习3-3 编写函数 expand(s1, s2),将字符串s1 中类似于a-z 一类的速记符号在字符串s2中扩展为等价的完整列表abc…xyz。该函数可以处理大小写字母和数字。
- ACM小练习之字符串的处理
- zoj1151 I - Word Reversal 【简单字符串处理】【第三周练习】【the first day】
- 字符串处理的练习~
- 【基础练习】【字符串处理】codevs1264 芳香数题解
- C# 实例练习——字符串处理(第三天)
- JavaScript常用字符串处理函数
- oracle的一种字符串处理机制。
- java练习1——识别字符串中出现英文字母的次数