Last active
November 21, 2017 04:48
-
-
Save David-Hackro/d8dad4277322f6735af4dae4a40f0b0d to your computer and use it in GitHub Desktop.
exercises in java
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
package crackingcodeinterview; | |
public class Exercise { | |
static String textString = "this is a random text of example"; | |
public static void main(String[] args) { | |
filterLetters(0, ""); | |
} | |
public static void filterLetters(int position, String letters) { | |
if (position != textString.length()) { | |
boolean p = false; | |
for (int i = 0; i < letters.length(); i++) { | |
if (letters.charAt(i) == textString.charAt(position)) { | |
p = true; | |
break; | |
} | |
} | |
if (!p) { | |
letters += textString.charAt(position); | |
} | |
position++; | |
filterLetters(position, letters); | |
} else { | |
System.out.println(letters); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i need change this solution, becase i cant use the substring because create a new string constantly :(