Question: /** * Mastery Test Week 3 Exercise 1. Thread 1. * - Swap two numbers. * * @author (your name) */ import java.util.Arrays; public class

/** * Mastery Test Week 3 Exercise 1. Thread 1. * - Swap two numbers. * * @author (your name) */ import java.util.Arrays; public class Swap { public static int[] swap(int[] numbers) { // In the coming weeks, the lecturer will explain all of the code above. But for now here is an explanation: // 1. In the code above we have provided an integer array "numbers", containing two elements. // In the space provided below, write code to swap the values in "numbers[0]" and "numbers[1]". // Do NOT initialise "numbers[0]" or "numbers[1]". Just write the three lines that swap the values. // Add your code BELOW this line. Do NOT change anything ABOVE this comment line. int temp=numbers[0]; numbers[0]=numbers[1]; numbers[1]=temp; // Add your code ABOVE this line. Do NOT change anything BELOW this comment line. return numbers; // Do NOT chage this line of code } // do NOT change anything below this line public static void main(String[] args) { int[] numbers = {1, 2}; System.out.println("initially the array was: " + Arrays.toString(numbers)); System.out.println("After calling Swap method, the array is: " +Arrays.toString(swap(numbers))); } }

For this one you start with a hard-coded, but large-ish, array.

Your job is to print out, on separate lines, the length of the array, then each element in order they appear in the array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!