id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2024_11_21_APP1SLHL_swapIndex
prev  |  next  |  chance

Write a method that has an integer array input parameter 'nums', and two interger parameters 'swap1' and 'swap2'. Return 'nums' but with the numbers at indices 'swap1' and 'swap2' swapped. For example, if 'nums' is {1,2,3,4,5,6,7}, 'swap1' is 0 and 'swap2' is 6 you would return {7,2,3,4,5,6,1}. Look at the test data for more examples. Preconditions: 'nums' will be a non-empty array of integers. Both 'swap1' and 'swap2' will be between 0 and the greatest index of 'nums', inclusive. Note that 'swap1' could equal 'swap2'. NOTE: "indices" is the plural for "index".


test2024_11_21_APP1SLHL_swapIndex([4, 5], 0, 1) → [5, 4]
test2024_11_21_APP1SLHL_swapIndex([7], 0, 0) → [7]
test2024_11_21_APP1SLHL_swapIndex([800, 400, 100, 5], 0, 3) → [5, 400, 100, 800]

...Save, Compile, Run (ctrl-enter)

public int[] test2024_11_21_APP1SLHL_swapIndex(int[] nums, int swap1, int swap2) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 280

Copyright Nick Parlante 2017 - privacy