public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
int count = 0;
// breaking in to characters
char[] str1 = s1.toCharArray();
System.out.println("Duplicate are :");
//creating outer loop for string length
for (int i = 0; i < s1.length(); i++) {
//creating inner loop for comparison
for (int j = i + 1; j < s1.length(); j++) {
//comparing value of i and j
if (str1[i] == str1[j]) {
System.out.println(str1[j]);
System.out.println(count);
//increment after comparison
count++;
break;
}
}
}
sc.close();
}
输出:
aassdesdd
Duplicate are :
a
s
s
d
d
凤凰求蛊
ABOUTYOU
相关分类