Java 编程题目 第七题

来源:互联网 发布:dede淘宝客api采集 编辑:程序博客网 时间:2024/06/05 11:22

package com.liuhuan.test;import java.util.Scanner;public class fun07 {/* *    题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。    */public static void main(String[] args) {// TODO Auto-generated method stubint English=0,number=0,Space=0,others=0;System.out.println("请输入字符串:");        Scanner input=new Scanner(System.in);        String str=input.nextLine();        char[] Char_str=str.toCharArray();        for(int i=0;i<Char_str.length;i++){        char ch=Char_str[i];         if(('z'>=ch&&ch>='a')||('A'<=ch&&ch<='Z')){           English++;         }         else if(ch>='0'&&ch<='9'){          number++;          }         else if(ch==' '){          Space++;          }        else others++;  }        System.out.println("英文字母"+English+"\r空格="+Space+"\r数字="+number+"\r其它字符="+others);  }}


原创粉丝点击