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

    题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

    程序分析:利用while语句,条件为输入的字符不为 ' '. 

     1 package com.li.FiftyAlgorthm;
     2 
     3 import java.util.Scanner;
     4 
     5 /**
     6  * 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 
     7  * 
     8  * 程序分析:利用while语句,条件为输入的字符不为 '
     '
     9  * @author yejin
    10  */
    11 public class CharacterStatistics {
    12     static int digital = 0;
    13     static int character = 0;
    14     static int other = 0;
    15     static int blank = 0;
    16 
    17     public static void main(String[] args) {
    18         char[] ch = null;
    19         Scanner sc = new Scanner(System.in);
    20         String s = sc.nextLine();
    21         ch = s.toCharArray();
    22 
    23         for (int i = 0; i < ch.length; i++) {
    24             if (ch[i] >= '0' && ch[i] <= '9') {
    25                 digital++;
    26             } else if ((ch[i] >= 'a' && ch[i] <= 'z') || ch[i] > 'A'
    27                     && ch[i] <= 'Z') {
    28                 character++;
    29             } else if (ch[i] == ' ') {
    30                 blank++;
    31             } else {
    32                 other++;
    33             }
    34 
    35         }
    36         System.out.println("数字个数: " + digital);
    37         System.out.println("英文字母个数: " + character);
    38         System.out.println("空格个数: " + blank);
    39         System.out.println("其他字符个数:" + other);
    40     }
    41 }
  • 相关阅读:
    android cts 命令的说明
    k8s认证授权和dashboard部署
    Pod对象的基本概念
    k8s创建自定义资源
    flannel网络插件介绍
    go语言包的介绍
    安装k8s的自动代码生成器
    k8s的pv和pvc概念
    Es索引匹配查询
    shell实现自动化部署项目
  • 原文地址:https://www.cnblogs.com/justdoitba/p/7142719.html
Copyright © 2011-2022 走看看