package com.tutorial4u;
import java.util.HashSet;
import java.util.Scanner;
public class DuplicateCharCount {
public static void main(String[] args) {
int count = 0;
System.out.print("Enter any String : ");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[] ch = str.toCharArray();
System.out.print("Duplicate character are : ");
for(int i = 0;i<ch.length;i++){
for(int j = i+1;j<ch.length;j++){
if((ch[i] == ch[j]) && (i!=j)){
System.out.print(ch[i]);
count++;
break;
}
}
}
}
}
Enter
any String : tutorial4u
Duplicate character are :
tu
No comments:
Post a Comment