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

 

simona1@sfusd.edu sorting > swap
prev  |  next  |  chance

Swaps the elements at index1 and index2 of array a, then returns the array. Precondition: a will have a length of 2 or greater.


swap([1, 3, 5, 7], 0, 3) → [7, 3, 5, 1]
swap([1, 3, 99], 0, 1) → [3, 1, 99]
swap([1, 3, 99], 1, 2) → [1, 99, 3]

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

public int [] swap(int [] a, int index1, int index2){ }

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: 349 Post-solution available

Copyright Nick Parlante 2017 - privacy