zoukankan      html  css  js  c++  java
  • JAVA 统计键盘输入的一个字符串中的数字,字母大小写和其他。

    package Code503;

    import java.util.Scanner;
    /*
    题目:
    统计键盘输入的一个字符串中的数字,字母大小写和其他。
    */

    public class CodeStringCount {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("请输入一个字符串");
    String input = scanner.next();
    int countUpper = 0;
    int countLower = 0;
    int countNumber= 0;
    int countOther= 0;
    //将字符串转为字符数组
    char[] array = input.toCharArray();
    for (int i = 0; i < array.length; i++) {
    char ch = array[i];
    if ('A'<=ch&&ch<='Z'){
    countUpper++;
    }else if ('a'<=ch&&ch<='z'){
    countLower++;
    }else if ('0'<=ch&&ch<='9'){
    countNumber++;
    }else{
    countOther++;
    }
    }
    System.out.println("Lower"+countLower+"Upper"+countUpper+"Number"+countNumber+"Other"+countOther);
    }
    }
    运行代码↓


  • 相关阅读:
    c语言中统计字符串中数字出现的次数
    tyvj1294 小v的舞会
    tyvj1114 搭建双塔
    tyvj1193 括号序列
    tyvj1113 魔族密码
    tyvj1102 单词的划分
    tyvj1097 mm不哭
    tyvj1189 盖房子
    tyvj1098 任务安排
    tyvj1144 股票
  • 原文地址:https://www.cnblogs.com/Ssinoo/p/10806932.html
Copyright © 2011-2022 走看看