输入一行字符,分别统计出包括英文字母、空格、数字和其他字符的个数
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); } }
posted on 2017-06-22 15:19 yjbjingcha 阅读(216) 评论(0) 编辑 收藏 举报