标签:
import java.util.Scanner; public class GetNumDifChar { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); int isLetter = 0; int isSpace = 0; int isDigit = 0; int isOther = 0; for (int i = 0; i < str.length(); i++) { if(Character.isLetter(str.charAt(i))) isLetter++; else if(Character.isSpace(str.charAt(i))) isSpace++; else if(Character.isDigit(str.charAt(i))) isDigit++; else isOther++; } System.out.println(isLetter); System.out.println(isSpace); System.out.println(isDigit); System.out.println(isOther); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数
标签:
原文地址:http://blog.csdn.net/liaction/article/details/47843791