java--遍历字符串

package com.test;

public class zifuchuanbianli {
public static void main(String[] args) {
String s ="ABCDEabcdef123456!@#$%%^";
int big = 0;
int small = 0;
int num = 0;
int other = 0;
for(int i=0;i<s.length();i++) {
//System.out.println(s.charAt(i));
char c = s.charAt(i); //通过索引拿取每一个字符
//判断是否在此范围之内
if(c >= 'A' && c <= 'Z') {
big++; //如果满足大写,计数器递增
}else if(c >= 'a' && c <= 'z'){
small++;
}else if(c >= '0' && c <= '9') {
num++;
}else {
other++;
}
}
System.out.println("大写字母"+big);
System.out.println("小写字母"+small);
System.out.println("数字"+num);
System.out.println("其他"+other);
}
}

******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
原文地址:https://www.cnblogs.com/cloudLi/p/12936826.html