输入一行字符,分别统计出其中的英文字母,空格,数字和其他字符的个数
2013-02-18 20:43
591 查看
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入字符串:");
String a = s.nextLine();
int abccount = 0;
int numcount = 0;
int spacecount = 0;
int othercount = 0;
char[] b = a.toCharArray();
for(int i = 0; i < b.length; i++){
if(b[i]>='a'&&b[i]<='z'||b[i]>='A'&&b[i]<='Z'){
abccount++;
}else if(b[i]>='0'&&b[i]<='9'){
numcount++;
}else if(b[i]==' '){
spacecount++;
}else{
othercount++;
}
}
System.out.println("字符串中含有的英文字母数为:" + abccount);
System.out.println("字符串中含有的数字数为:" + numcount);
System.out.println("字符串中含有的空格数为:" + spacecount);
System.out.println("字符串中含有的其他字符为:" + othercount);
}
}
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入字符串:");
String a = s.nextLine();
int abccount = 0;
int numcount = 0;
int spacecount = 0;
int othercount = 0;
char[] b = a.toCharArray();
for(int i = 0; i < b.length; i++){
if(b[i]>='a'&&b[i]<='z'||b[i]>='A'&&b[i]<='Z'){
abccount++;
}else if(b[i]>='0'&&b[i]<='9'){
numcount++;
}else if(b[i]==' '){
spacecount++;
}else{
othercount++;
}
}
System.out.println("字符串中含有的英文字母数为:" + abccount);
System.out.println("字符串中含有的数字数为:" + numcount);
System.out.println("字符串中含有的空格数为:" + spacecount);
System.out.println("字符串中含有的其他字符为:" + othercount);
}
}
相关文章推荐
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。。。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数【while循环】
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 6.2输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符 分别统计其中英文字母 空格 数字 和其他字符的个数
- 华为oj_输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 50道编程题之07:输入一行字符,分别统计出其中的英文字母,空格,数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母 空格 数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。.Cpp
- 输入一行字符,分别统计出其中英文字母 空格 数字 和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
- c语言:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
- (c++)输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
- 输入一行字符,分别统计出其中的英文字母、空格、数字、和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数
- c语言:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。