package 用户登录;
//判断键盘录入的单词有由那些构成
import java.util.Scanner;
public class StringDem5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String str = sc.next();
int count1 = 0;
int count2 = 0;
int count3 = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= 'a' && c <= 'z') {
count1++;
} else if (c >= 'A' && c <= 'Z') {
count2++;
} else if (c >= '0' && c <= '9') {
count3++;
}
}
System.out.println("小写字母有:"+count1);
System.out.println("大写字母有:"+count2);
System.out.println("数字有"+count3);
}
}
判断一个单词的字母 数字等的构成数量
最新推荐文章于 2024-09-08 12:41:07 发布