统计数字类型的String数组中各个元素的个数
来源:互联网 发布:淘宝卖家规则 编辑:程序博客网 时间:2024/05/22 00:11
public class Test {
public static void main(String[] args) {
String[] str = { "1", "2", "2", "2", "5", "5", "5", "4", "3", "3" };
先排序在操作。
String in = "";
for (int i = 0; i < str.length; i++) {
for (int j = i + 1; j < str.length; j++) {
if (Integer.parseInt(str[i]) > Integer.parseInt(str[j])) {
in = str[j];
str[j] = str[i];
str[i] = in;
}
}
}
for (int i = 0; i < str.length; i++) {
System.out.println(str[i]);
}
for (int i = 0; i < str.length; i++) {
for (int j = i; j < str.length; j++) {
if (Integer.parseInt(str[j]) > Integer.parseInt(str[i])) {
System.out.println(str[i] + "..........." + (j - i));
i=j-1;
break;
}
}
if (Integer.parseInt(str[i]) == Integer.parseInt(str[str.length-1])) {
System.out.println(str[i] + "..........." + (str.length-i));
break;
}
}
}
}
运行结果
1
2
2
2
3
3
4
5
5
5
1...........1
2...........3
3...........2
4...........1
5...........3
1 0
- 统计数字类型的String数组中各个元素的个数
- 统计数字字符的个数
- 统计数字字符的个数
- 统计列表中各个元素的个数并输出
- String中统计数字,字母,汉字等个数
- 得到动态数组中元素的个数
- 数组中有效元素个数的统计
- 数组中存储不定个数的元素
- 求数组中不同元素的个数
- 查询数组中相同元素的个数
- 求数组中各个数的个数出现次数
- 1065: 统计数字字符的个数
- 统计数字1~n中各位数的个数
- 统计数字二进制中1的个数(分治法)
- 根据hash统计数组中各个元素的数量
- 根据数组名求数组中元素的个数
- 获取数组元素的个数
- 求数组中元素个数,数组类型随意
- Markdown 语法入门
- javaScript笔记(十二) 匿名函数和闭包
- 关联源码
- MySQL:MHA安装配置
- nginx配置遇到的问题与解决方法(nginx.conf正则)
- 统计数字类型的String数组中各个元素的个数
- XSLT语法 在.net中使用XSLT转换xml文档示例
- nginx 413 Request Entity Too Large
- 常与同好争高下 不公傻瓜论短长
- Bloom Filter原理
- POJ-1459 Power Network
- hdu 5142 物理三分算法
- [平方的拆分 DP] BZOJ 1566 [NOI2009]管道取珠
- sql优化-索引介绍