Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 18. The method to swap array elements works because, unlike integers, arrays are objects and use reference semantics.
- 19.
- 2 [0, 0, 1, 0]
- 1 [0, 0, 1, 0]
- 3 [0, 0, 1, 1]
- 2 [0, 0, 1, 1]
- 20.
- 2 [0, 1]
- 1 [0, 1]
- 1 [1, 2]
- 0 [1, 2]
- 21.
- public static void swapPairs(int[] list) {
- for (int i = 0; i < list.length - 1; i += 2) {
- swap(list, i, i + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement