题目
输入
输入一行字符串,可以有空格
输出
统计其中英文字符,空格字符,数字字符,其他字符的个数
样例输入 1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\/;p0-=\][
样例输出 26 3 10 12
============================================================
题目得分98
第一次忘了修改类名为main 编译错误
===========================================
import java.util.Scanner;
public class oj003 {
public void count(String str)
{
int word=0;
int tab=0;
int number=0;
int other=0;
//使用循环遍历所有字符 统计出现次数
for(int i=0;i<str.length();i++)
{
char c=str.charAt(i);
if(c>='a'&&c<='z') //小写字母
{
word++;
}
else if(c>='A'&&c<='Z') //大写字母
{
word++;
}
else if(c>='0'&&c<='9') //数字
{
number++;
}
else if(c==' ') //空格
{
tab++;
}
else //其他
{
other++;
}
}
System.out.println(word);
System.out.println(tab);
System.out.println(number);
System.out.println(other);
return ;
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String str=scanner.nextLine();
new oj003().count(str);
}
}