import java.util.Scanner;
public class Chupapi {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
String str = "";
System.out.print("Enter string: ");
str = input.nextLine();
getConsonantCount(str);
}
public static void getConsonantCount(String str) {
char string[] = str.toCharArray();
System.out.print("Duplicate characters in a given string: ");
for(int i = 0, count = 0; i <string.length; i++) {
count = 1;
for(int j = i+1; j <string.length; j++) {
if(string[i] == string[j] && string[i] != ' ') {
count++;
string[j] = '0';
}
}
if(count > 1 && string[i] != '0')
System.out.print(string[i]);
}
}
}
我想对“给定字符串中的重复字符”进行分类:“按字母顺序的输出示例是,
"Duplicate characters in a given string: heuro"
I want it to be
"Duplicate characters in a given string: ehoru"
这就是我想用这段代码做的所有事情,关于我应该做什么或使用什么的提示?
1条答案
按热度按时间g0czyy6m1#
在查找重复字符之前,请使用arrays.sort()对数组进行排序。