标签:next class char scanner 中英文 length main imp print
/*
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
*/
import java.util.*;
public class Class7 {
public static void main(String[] args){
int zimu = 0;
int kongge = 0;
int shuzi = 0;
int qita = 0;
char[] ch = null;
System.out.println("请输入:");
Scanner s = new Scanner(System.in);
String sg = s.nextLine();
ch = sg.toCharArray();
for(int i = 0; i < ch.length; i++){
if((ch[i] >= ‘a‘ && ch[i] <= ‘z‘) || (ch[i] >= ‘A‘ && ch[i] <= ‘Z‘)){
zimu++;
}else if(ch[i] == ‘ ‘){
kongge++;
}else if(ch[i] >= ‘0‘ && ch[i] <= ‘9‘){
shuzi++;
}else{
qita++;
}
}
System.out.println("字母:" + zimu);
System.out.println("空格:" + kongge);
System.out.println("数字:" + shuzi);
System.out.println("其他:" + qita);
}
}
标签:next class char scanner 中英文 length main imp print
原文地址:https://www.cnblogs.com/zhuozige/p/12357963.html