zoukankan      html  css  js  c++  java
  • 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);
    }
    }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    数与bit
    ARM汇编优化1
    一 *(a+1)与*(&a+1)
    二 *(a+1)多维数组
    三 二维数组取址
    四 sizeof(a)
    永恒之蓝及WannaCry分析
    github使用记录
    三种页面置换算法的C++模拟
    opencv检测图像直线
  • 原文地址:https://www.cnblogs.com/cloudLi/p/12936826.html
Copyright © 2011-2022 走看看