字符串中出现的相同字母的个数
来源:互联网 发布:数据脱敏的常用方法 编辑:程序博客网 时间:2024/05/16 09:58
方法一:
public class Helloson1{
private static String s="abcdbcdabdefg";
private static char s1[]=s.toCharArray();
private static String s2="";
static int count=0;
static int count1=0;
public static void main(String[] args) {
/*for(int i=0;i < s1.length;i++){
System.out.println(s1[i]);
}*/
/*把字符串中不重复的放在一个字符串中*/
for(int i=0;i<s1.length;i++){
if(s2.indexOf(s1[i])<0)
{
count++;
s2=s2+s1[i];
}
}
char []temp=s2.toCharArray();
for(int i=0;i<temp.length;i++)
{
count1=0;
for(int j=0;j<s1.length;j++){
if(temp[i] == s1[j])
{
count1++;
}
}
System.out.println(temp[i]+" "+count1);
}
}
}
方法二:
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Helloson1{
private static String s="hello world";
private static Set set=new HashSet<>();
private static int count=0;
public static void main(String[] args) {
for(int i=0;i<s.length();i++){
set.add(s.charAt(i));
}
System.out.println(set);
Iterator it=set.iterator();
while(it.hasNext())
{
count=0;
String s1=(String)it.next().toString();
for(int j=0;j<s.length();j++){
if(s1.equals(s.substring(j,j+1)))
{
count++;
}
}
System.out.println(s1+" "+count);
}
}
}
- 字符串中出现的相同字母的个数
- 统计字符串中字母出现的个数
- 获取字符串中字母出现的个数
- 字符串中各个字母出现的个数
- 在一个字符串中输入若干字母,统计该数组中出现的相同字母的个数。
- 16周:统计字符串中数字、字母出现的个数。
- 【叶子函数分享六】求两个字符串中相同的汉字及字母的个数
- 【叶子函数分享六】求两个字符串中相同的汉字及字母的个数
- 求两个字符串中相同的汉字及字母的个数
- 统计一个字符串中大小写字母的个数,数字出现的个数
- c# 如何判断字符串中相同字符串的个数 (相同字符在字符串中出现的次数)
- 统计字符串中相同字符的个数
- 统计字符串中大小写字母的个数
- 统计字符串中每个字母的个数
- 统计字符串中每个字母的个数
- 第13周项目5字符串操作-统计字符串中大小写字母出现的个数
- 第13周项目5字符串操作-统计字符串中字母出现的个数
- 字符串统计の每个字母出现的个数
- Linux文件写过程分析一(写过程中的锁)
- java中URL和File的相互转化
- 警惕通过数据库的破解取得操作系统管理员权限
- [leetcode]Best Time to Buy and Sell Stock III
- jquery中animate动画的小例子
- 字符串中出现的相同字母的个数
- jquery 操作checkbox
- <算法设计技巧与分析>M.H>Alsuwaiye编著 读书心得
- L2C码表的产生
- ClickOnce部署(2):自动更新
- 部落化的互联网生态,5个不同的思考维度
- 道德经之自胜者强
- DataTable数据检索的性能分析
- 几个常用的自定义js方法