public class test9 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String src=sc.nextLine();
judge(src);
}
static void judge(String src){
int Rem=0; //记录重复字符数
int[] ch=new int[128]; //用于记录重复的字符
for (int i = 0; i < src.length(); i++) {
int index=(int)src.charAt(i); //将字符转化为ASCill码,对应的index就是字符的ASCILL码
ch[index]++; //巧用下标,将字符的ASCILL码作为辅助数组的下标,将其对应位置+1,记录出现字符的次数
}
for (int i = 0; i < ch.length; i++) { //遍历数组
if (ch[i]>1) { //字符个数超过一个,字符重复
System.out.println("字符"+(char) i + "重复");
Rem++;
}
}
if (Rem==0)
System.out.println("无字符重复");
}
}
05-13
06-27
2028
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-21
5万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-22
1146
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交