Advertisement
willieshi232

Untitled

Dec 8th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. 18. The method to swap array elements works because, unlike integers, arrays are objects and use reference semantics.
  2. 19.
  3. 2 [0, 0, 1, 0]
  4. 1 [0, 0, 1, 0]
  5. 3 [0, 0, 1, 1]
  6. 2 [0, 0, 1, 1]
  7. 20.
  8. 2 [0, 1]
  9. 1 [0, 1]
  10. 1 [1, 2]
  11. 0 [1, 2]
  12. 21.
  13. public static void swapPairs(int[] list) {
  14. for (int i = 0; i < list.length - 1; i += 2) {
  15. swap(list, i, i + 1);
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement