Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String[] original = {"The", "quick", "Brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] mixed = mixArray(original);
- ArrayList<String> sameOrder = new ArrayList<>();
- int wordsInTheSameOrder = 0;
- for(int i = 0; i < original.length; i++) {
- if(original[i].equals(mixed[i])) {
- sameOrder.add(original[i]);
- wordsInTheSameOrder++;
- }
- }
- int howMany = 0;
- String [] words = originalString.split(',');
- Map <String, Integer> position = new HashMap <>();
- for(int i = 0; i < words.length; i++){
- String word = words[i];
- position[word] = i;
- }
- String [] otherWords = newString.split(',');
- for(int i = 0; i < otherWords.length; i++){
- String word = words[i];
- howMany += position[word] == i;
- }
- System.out.println(howMany);
- val str = "The quick brown fox jumps over the lazy dog"
- val list = str.split(" ")
- val strShuffled = "over jumps brown The lazy fox quick the dog"
- val listShuffled = strShuffled.split(" ")
- println(list.filterIndexed { index, s -> s.equals(listShuffled[index])}.size)
Add Comment
Please, Sign In to add comment