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