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);
    }
    }

    ******************************人因为有理想、梦想而变得伟大,而真正伟大就是不断努力实现理想、梦想*****************************
  • 相关阅读:
    Docker理解
    提高服务器并发量,有关系统配置的常规方法
    Linux EXT 文件系统 详解
    jvm入门
    2020-1-08.运维面试题总结
    hexo+gitee
    rsync
    haddop3.2.1完全分布式安装
    zabbix02
    zabbix监控工具问题集
  • 原文地址:https://www.cnblogs.com/cloudLi/p/12936826.html
Copyright © 2011-2022 走看看