zoukankan      html  css  js  c++  java
  • 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

    public static void main(String[] args) {
    //输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
    String str="ABab哈哈 123,";
    int letter=0;//字母
    int space=0;//空格
    int number=0;//数字
    int other=0;//其他
    for (int i = 0; i < str.length(); i++) {
    char ch=str.charAt(i);//从字符串中获取字符
    if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){
    letter++;
    }else if(ch==' '){//空格
    space++;
    }else if(ch>='0'&&ch<='9'){//数字
    number++;
    }else {
    other++;
    }
    }
    System.out.println("英文字母的个数是:"+letter+",空格的个数是:"
    +space+",数字的个数是:"+number+",其他的个数是:"+other);
    }

  • 相关阅读:
    asp.net读取/导入project(mpp)文件
    hdu2103
    hdu2100(大数加)
    hdu1406
    hdu1249
    hdu1038
    hdu2565
    hdu1203
    zoj3501
    hdu2102
  • 原文地址:https://www.cnblogs.com/sunda847882651/p/9459391.html
Copyright © 2011-2022 走看看