统计字符串中的数字,大写字符,小写字符个数
2018-02-24 15:04
253 查看
public class CharacterTest { public static void main(String[] args) { //首先定义一个字符串 String str = "Adu123Messi"; //然后让我们定义三个统计变量 int bigCount = 0;//大写字母 int smallCount = 0;//小写字母 int numberCount = 0;//数字 // 把字符串转换为字符数组。 char[] chs = str.toCharArray(); // 遍历字符数组获取到每一个字符 for (int x = 0; x < chs.length; x++) { char ch = chs[x]; // 判断该字符 if (Character.isUpperCase(ch)) { bigCount++; } else if (Character.isLowerCase(ch)) { smallCount++; } else if (Character.isDigit(ch)) { numberCount++; } } // 输出结果 System.out.println("大写字母:" + bigCount + "个"); System.out.println("小写字母:" + smallCount + "个"); System.out.println("数字字符:" + numberCount + "个"); } }
相关文章推荐
- 练习三:统计字符串中字符中 大写字符 小写字符 数字 其他字符 出现的次数
- 从键盘输入一个带有数字的字符串,将其中所在的数字的位置输出,并把数字串小写字符变大写字符再输出
- Java基础知识强化69:基本类型包装类之Character案例(统计字符串中大写小写以及数字的次数)
- 设计一个函数实现将一个字符串中的大写字符变为小写字符,小写字符变为大写字符,数字不变,删除其他字符
- 常见对象-统计大写,小写及数字字符的个数案例
- java例题学习:统计大写,小写及数字字符的个数案例
- 常见对象_统计字符串中大写小写以及数字出现的次数案例
- 常见对象_统计大写,小写及数字字符的个数案例
- 通过程序统计字符串的大写字母个数、小写字母个数、数字个数和其它字符个数。用函数func实现功能
- c++实验5--统计输出字符串中(大/小写)字母个数,数字个数及其它字符个数。
- 输入一串字符串,运用输出方法计算其中大写 小写 数字 和其他字符的个数
- C# 删除字符串中除字母和数字之外的其它字符,C#将字符串中的大写转小写,小写转大写
- 常见对象-统计字符串中大写小写以及数字出现的次数案例
- C# 字符、字符串过滤,只能输入数字、中文、英文、大写、小写(转)
- C# 字符、字符串过滤,只能输入数字、中文、英文、大写、小写
- //1.编写代码模拟三次密码输入的场景。//2.编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出。
- 统计一个字符串中英文字母、空格、数字和其它字符的个数
- 习题 7.9 编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格、和其他字符的个数,在主函数中输入字符串以及输出上述的结果。
- 输入一个字符串,统计该字符串中分别包含多少个数字,多少个字母,多少个其他字符
- 编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出。