count_char

import java.util.Scanner;
public class count_char
{
	public static void main(String args[])
	{
		int count1=0,count2=0,count3=0,count4=0;
		String str;
		Scanner reader = new Scanner(System.in);
		
		while((str=reader.nextLine())!=null)
		{
			char temp[]=str.toCharArray();
			for(int i=0; i<temp.length; i++)
			{
				if(Character.isLetter(temp[i])) count1++;
				else if (Character.isDigit(temp[i])) count2++;
				else if (Character.isWhitespace(temp[i])) count3++;
				else count4++;
			}
			System.out.printf("letter:%d  number:%d  Whitespace:%d another:%d \n"
			, count1, count2, count3, count4);
			str="";
		}
	}
}

posted on 2017-10-27 11:20  MACHINE_001  阅读(109)  评论(0编辑  收藏  举报

导航