Created
December 19, 2018 17:40
-
-
Save AnkDos/c05163a6a5d696ed05a47ad409e3ce9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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