Guest User

Untitled

a guest
Oct 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. String[] original = {"The", "quick", "Brown", "fox", "jumps", "over", "the", "lazy", "dog"};
  2. String[] mixed = mixArray(original);
  3. ArrayList<String> sameOrder = new ArrayList<>();
  4. int wordsInTheSameOrder = 0;
  5. for(int i = 0; i < original.length; i++) {
  6. if(original[i].equals(mixed[i])) {
  7. sameOrder.add(original[i]);
  8. wordsInTheSameOrder++;
  9. }
  10. }
  11.  
  12. int howMany = 0;
  13.  
  14. String [] words = originalString.split(',');
  15. Map <String, Integer> position = new HashMap <>();
  16. for(int i = 0; i < words.length; i++){
  17. String word = words[i];
  18. position[word] = i;
  19. }
  20.  
  21. String [] otherWords = newString.split(',');
  22. for(int i = 0; i < otherWords.length; i++){
  23. String word = words[i];
  24. howMany += position[word] == i;
  25. }
  26.  
  27. System.out.println(howMany);
  28.  
  29. val str = "The quick brown fox jumps over the lazy dog"
  30. val list = str.split(" ")
  31.  
  32. val strShuffled = "over jumps brown The lazy fox quick the dog"
  33. val listShuffled = strShuffled.split(" ")
  34.  
  35. println(list.filterIndexed { index, s -> s.equals(listShuffled[index])}.size)
Add Comment
Please, Sign In to add comment