package hhxy;
import java.util.Scanner;
/**
* @author HF
* 检查输入中的字符串中的各种类型
*
*/
public class Check {
public static void main(String[] args) {
int abcCount = 0;
int spaceCount = 0;
int numCount = 0;
int otherCount = 0;
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
if (Character.isDigit(ch[i])) {
numCount++;
} else if (Character.isSpaceChar(ch[i])) {
spaceCount++;
} else if (Character.isLetter(ch[i])) {
abcCount++;
} else {
otherCount++;
}
}
System.out.println("字母个数"+abcCount);
System.out.println("数字个数"+numCount);
System.out.println("空格个数"+spaceCount);
System.out.println("其他字符个数"+otherCount);
}
}
import java.util.Scanner;
/**
* @author HF
* 检查输入中的字符串中的各种类型
*
*/
public class Check {
public static void main(String[] args) {
int abcCount = 0;
int spaceCount = 0;
int numCount = 0;
int otherCount = 0;
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
if (Character.isDigit(ch[i])) {
numCount++;
} else if (Character.isSpaceChar(ch[i])) {
spaceCount++;
} else if (Character.isLetter(ch[i])) {
abcCount++;
} else {
otherCount++;
}
}
System.out.println("字母个数"+abcCount);
System.out.println("数字个数"+numCount);
System.out.println("空格个数"+spaceCount);
System.out.println("其他字符个数"+otherCount);
}
}