package JavaExam;
import java.util.Scanner;
public class JavaExam11 {
public static void main(String[] args) {
//定义变量
int abc=0;
int space=0;
int other=0;
int num = 0;
//接受信息
Scanner scr = new Scanner(System.in);
System.out.println("请输入一组字符串" );
String str =scr.nextLine();
//提供一个数组接收字符串
char [] chars =str.toCharArray();
//for循环条件判断
for (int i = 0;i<chars.length;i++){
//调用类库判断是否为字母数字等
if (Character.isLetter(chars[i])){
abc++;
}else if (Character.isDigit(chars[i])){
num++;
}else if (Character.isSpaceChar(chars[i])){
space++;
}else {
other++;
}
}
System.out.println("字母个数"+abc);
System.out.println("数字个数"+num);
System.out.println("空格个数"+space);
System.out.println("其他个数"+other);
}
}
输入一行字符,分别计算出其中英文字符,数字,其它符号的个数
最新推荐文章于 2023-06-19 09:30:13 发布