Skip to content

Instantly share code, notes, and snippets.

@AnkDos
Created December 19, 2018 17:40
Show Gist options
  • Save AnkDos/c05163a6a5d696ed05a47ad409e3ce9f to your computer and use it in GitHub Desktop.
Save AnkDos/c05163a6a5d696ed05a47ad409e3ce9f to your computer and use it in GitHub Desktop.
import java.util.*;
public class Ankdos{
static int count(char letter , String word ){
int i = 0,counts = 0 ;
while(i<word.length()){
if (letter == word.charAt(i) ){
counts++;
}
i++;
}
return counts;
}
static String reps(String word){
int i = 0 ,k=0;
String reps = "";
List<String> mark = new ArrayList<String>(); //to mark the repeated character
while(i < word.length()){
if(count(word.charAt(i),word) > 1 && mark.contains(Character.toString(word.charAt(i))) == false ){
reps += Character.toString(word.charAt(i));
mark.add(Character.toString(word.charAt(i)));
reps +=" ";
k++;
}
i++;
}
return reps;
}
public static void main(String []args){
String word = "ankuarawquijvkjsdvr";
System.out.println(reps(word));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment