输入一行字符 分别统计其中英文字母 空格 数字 和其他字符的个数
来源:互联网 发布:攻破网站数据库 编辑:程序博客网 时间:2024/06/07 14:01
/**
* @Description:输入一行字符 分别统计其中英文字母 空格 数字 和其他字符的个数
* @author :FLY
* @date :2017年8月10日
*/
public class TestDemo1 {
public static void main(String[] args) {
int count1 = 0;// 字母个数
int count2 = 0;// 空格个数
int count3 = 0;// 数字个数
int count4 = 0;// 其他个数
int length = args[0].length();
/**
* 使用character调用方法,判断字符的类型
*/
/*char x[] = args[0].toCharArray();
for (int i = 0; i < x.length; i++) {
if (Character.isDigit(x[i])) {
count2++;
} else if (Character.isLetter(x[i])) {
count1++;
} else if (Character.isSpace(x[i])) {
count3++;
} else {
count4++;
}
}*/
/**
* 对每一个字符做比较。
*/
// for (int i = 0; i < length; i++) {
// char c = args[0].charAt(i);
// if (c >= '0' && c <= '9') {// 数字 结果14
// count1++;
// } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {//
// 字母
// // 结果20
// count2++;
// } else if (c == ' ') {// 空格 结果10
// count3++;
// } else {// 其他 结果21
// count4++;
// }
// }
System.out.println("字符串长度----:" + length);
System.out.println("数字个数----:" + count1);
System.out.println("字母个数----:" + count2);
System.out.println("空格个数----:" + count3);
System.out.println("其他个数----:" + count4);
}
}
* @Description:输入一行字符 分别统计其中英文字母 空格 数字 和其他字符的个数
* @author :FLY
* @date :2017年8月10日
*/
public class TestDemo1 {
public static void main(String[] args) {
int count1 = 0;// 字母个数
int count2 = 0;// 空格个数
int count3 = 0;// 数字个数
int count4 = 0;// 其他个数
int length = args[0].length();
/**
* 使用character调用方法,判断字符的类型
*/
/*char x[] = args[0].toCharArray();
for (int i = 0; i < x.length; i++) {
if (Character.isDigit(x[i])) {
count2++;
} else if (Character.isLetter(x[i])) {
count1++;
} else if (Character.isSpace(x[i])) {
count3++;
} else {
count4++;
}
}*/
/**
* 对每一个字符做比较。
*/
// for (int i = 0; i < length; i++) {
// char c = args[0].charAt(i);
// if (c >= '0' && c <= '9') {// 数字 结果14
// count1++;
// } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {//
// 字母
// // 结果20
// count2++;
// } else if (c == ' ') {// 空格 结果10
// count3++;
// } else {// 其他 结果21
// count4++;
// }
// }
System.out.println("字符串长度----:" + length);
System.out.println("数字个数----:" + count1);
System.out.println("字母个数----:" + count2);
System.out.println("空格个数----:" + count3);
System.out.println("其他个数----:" + count4);
}
}
阅读全文
0 0
- 输入一行字符,分别统计出其中的英文字母,空格,数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。.Cpp
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数
- 6.2输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
- 输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符 分别统计其中英文字母 空格 数字 和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。。。
- 输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
- 习题 5.4 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符个数。
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数【while循环】
- 华为oj_输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- c语言:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
- (c++)输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
- SQL语句Group By和Having需要注意的地方
- jquery mobile中为页面添加返回按钮的两种方式
- Python学习日志(五)之数据结构
- 如何将自己本地的项目传到github上
- 不带.classpath的svn项目下载创建
- 输入一行字符 分别统计其中英文字母 空格 数字 和其他字符的个数
- HTML a标签去除下划线
- 【java数据结构】快速排序
- mongodb常用命令
- 花书学习笔记(1) 范数、特征分解、奇异值分解、伪逆、自信息
- Flomerics Floemc 6.1(lic carcak) 电磁兼容性的分析
- MapReduce计数器
- Phoenix的数据类型和操作符、函数
- [LintCode]371.用递归打印数字