//新人求分分啊啊啊啊啊啊
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Test
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //键盘输入流
StringBuffer sb = new StringBuffer(br.readLine());
Demo d = new Demo(sb);
System.out.println("字母的总数有:" + d.getCharCount());
System.out.println("数字的总数有:" + d.getNumberCount());
System.out.println("空格的总数有:" + d.getSpaceCount());
System.out.println("其它字符的总数有:" + d.getOtherCount());
}
}
class Demo
{
StringBuffer sb;
int charCount = 0; //字母
int spaceCount = 0; //空格
int numberCount = 0;//数字
int otherCount = 0; //其它字符
public Demo(StringBuffer sb) {
this.sb = sb;
for(int i=0;i<sb.length();i++)
{
if((sb.charAt(i)>='a' && sb.charAt(i)<='z') || (sb.charAt(i)>='A'&&sb.charAt(i)<='Z'))
{
charCount++;
}
else if(sb.charAt(i)==' ')
{
spaceCount ++;
}
else if(sb.charAt(i)>'0'&&sb.charAt(i)<'9')
{
numberCount++;
}
else
{
otherCount++;
}
}
}
public int getCharCount()
{
return charCount;
}
public int getSpaceCount()
{
return spaceCount;
}
public int getNumberCount()
{
return numberCount;
}
public int getOtherCount()
{
return otherCount;
}
}
|