are always switching positions in the list. Write a method called, studentswap,
ID: 3726751 • Letter: A
Question
are always switching positions in the list. Write a method called, studentswap, that takes a String array and two int values indexA and indexB as parameters and returns a String array where the names at indexA and indexB have switched positions. For example, given this array of students: String[] students "Deja", "Archie", "Yusef" Ozzy "Yexing, "Jacques" "Horst", After this call: resultArray studentswap (students, 1, 4); = The resultArray would contain these names in this order: [Deja, ozzy, Yusef, Horst, Archie, Yexing, Jacques) Note: Assume zero-based indexing, the students array has length 2 and the index parameters are within bounds of the student array- you don't have to check for that. You can use Array Test,java given to you to wite the method. Run the main to see the results. Enter your answer below. You can copy and paste from JGrasp. publie string t) studentswap (String t) etudenta, int indexa, indexB) f int t i-0; Karray.lengthiu+)fExplanation / Answer
As question only asks for the function, and it has been clearly told to not check for boundy condition like lenth of array and index should be under array length. So i am giving solution according to this only
Following is the function
public static String[] StudentaSwap(String [] Students, int indexA, int indexB)
{
String temp = Students[indexA];
Students[indexA] = Students[indexB];
Students[indexB] = temp;
return Students;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.