Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Ejemplo
- {
- public static void main(String[] args)
- {
- String word = "laoh";
- String wholeUni = "oallh oooahl oooahlll";
- findPattern(word, wholeUni);
- }
- public static void findPattern(String word, String wholeString){
- if(!word.isEmpty()){
- char[] seq = wholeString.toCharArray();
- String copy =new String(word);
- int total = word.length();
- for(int i = 0; i < seq.length; i++){
- if(copy.length() >= 0){
- int idx = copy.indexOf(seq[i]);
- int idxr = word.indexOf(seq[i]);
- if(idx >= 0 ){
- total--;
- copy = copy.substring(0, idx) + copy.substring(idx + 1);
- }else if(idx < 0 && idxr >= 0 && copy.length() == word.length() -1){
- continue;
- }
- else{
- total = word.length();
- copy = word;
- }
- }
- if(total == 0){
- System.out.println("Pattern found in: " +( i - (word.length() -1)) + "-" + i );
- }
- }
- }
- }
- public static String sortString(String inputString)
- {
- char tempArray[] = inputString.toCharArray();
- Arrays.sort(tempArray);
- return new String(tempArray);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement