Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Ejemplo
  4. {
  5.  
  6.  
  7.  
  8. public static void main(String[] args)
  9. {
  10. String word = "laoh";
  11. String wholeUni = "oallh oooahl oooahlll";
  12. findPattern(word, wholeUni);
  13.  
  14. }
  15. public static void findPattern(String word, String wholeString){
  16.  
  17. if(!word.isEmpty()){
  18. char[] seq = wholeString.toCharArray();
  19. String copy =new String(word);
  20. int total = word.length();
  21. for(int i = 0; i < seq.length; i++){
  22. if(copy.length() >= 0){
  23. int idx = copy.indexOf(seq[i]);
  24. int idxr = word.indexOf(seq[i]);
  25. if(idx >= 0 ){
  26. total--;
  27. copy = copy.substring(0, idx) + copy.substring(idx + 1);
  28. }else if(idx < 0 && idxr >= 0 && copy.length() == word.length() -1){
  29. continue;
  30. }
  31. else{
  32. total = word.length();
  33. copy = word;
  34. }
  35. }
  36. if(total == 0){
  37. System.out.println("Pattern found in: " +( i - (word.length() -1)) + "-" + i );
  38. }
  39.  
  40. }
  41. }
  42. }
  43.  
  44.  
  45.  
  46. public static String sortString(String inputString)
  47. {
  48. char tempArray[] = inputString.toCharArray();
  49. Arrays.sort(tempArray);
  50. return new String(tempArray);
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement