A Java method cannot update primitive type parameters. For example, the following method does not work as intended:
public class SwapTester
{
public static void falseSwap(int a, int b) // doesn't work
{
int temp = a;
a = b;
b = temp;
}
public static void main(String[] args)
{
int x = 3;
int y = 4;
falseSwap(x, y);
System.out.println(x + " " + y);
System.out.println("Expected: 4 3"); // test fails
}
}
Your task is to implement a method trueSwap that swaps two values that were placed into an array.