/**
* 项目:用Java编程实现用户输入一个字符串,统计字符串中大写字母、小写字母、数字、其他字符的个数
* 时间:2019/8/13
* 作者:郑翰林
*/
import java.util.Scanner;
public class Test4 {
public static void main(String[] args) {
System.out.print("请输入字符串:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int count = 0;
int bigCount = 0;
int smallCount = 0;
int other = 0;
for (int i = 0, len = str.length(); i < len; i++) {
char c = str.charAt(i);
if (c >= 'A' && c <= 'Z') {
bigCount++;
} else if (c >= 'a' && c <= 'z') {
smallCount++;
} else if (c >= '0' && c <= '9') {
count++;
}else{
other++;
}
}
System.out.println("大写字母:" + bigCount);
System.out.println("小写字母:" + smallCount);
System.out.println("数字:" + count);
System.out.println("其他字符:" + other);
}
}
用Java编程实现用户输入一个字符串,统计字符串中大写字母、小写字母、数字、其他字符的个数
最新推荐文章于 2024-03-22 21:19:33 发布