判断一个字符串大写小写,和数字出现的次数
生活随笔
收集整理的這篇文章主要介紹了
判断一个字符串大写小写,和数字出现的次数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 判斷一個字符串大寫小寫,和數字出現的次數*/
public class Demo4 {public static void main(String[] args) {String str = "A1baC51-*/";//將字符串轉為字符數組;char[] chars = str.toCharArray();int bigCount = 0, smallCount = 0, numCount = 0, count = 0;for (char c : chars) {if (c >= 'a' && c <= 'z') {//統計大寫字母出現的次數bigCount++;} else if (c >= 'A' && c <= 'Z') {//統計小寫字母出現的次數smallCount++;} else if (c >= '0' && c <= '9') {//統計數字出現的次數numCount++;} else {count++;}}System.out.println("字 符 串的總長度為: " + str.length());System.out.println("大寫字母出現的次數: " + bigCount);System.out.println("小寫字母出現的次數: " + smallCount);System.out.println("數 字 出 現 的次數: " + numCount);System.out.println("非法字符出現的次數: " + count);}
}
總結
以上是生活随笔為你收集整理的判断一个字符串大写小写,和数字出现的次数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多线程线程池的基本创建,使用方法
- 下一篇: 使用对象操作流程,读写文件