Question: Read the following code, write the result: public class TestPassArray Main method/ public static void main(String] args) f int[] a -1, 2 // Swap elements
Read the following code, write the result: public class TestPassArray Main method/ public static void main(String] args) f int[] a -1, 2 // Swap elements using the swap me thod System.out.println("Before invoking swap") System.out.println("array is " ato] swap(a [0], a[1]) System.out.println"After invoking swap) System.out.println("array is "a[o]al1]" // Swap elements using the swapFirstTwoInArray method System.out.println("Before invoking swapFirst TwoInArray) System.out.println("array is a[0]a[l]"" swapFirstTwoInArray(a); System.out.printIn After invoking swapFirstTwoInArray") System.out.printlnC"array is +a[o] + /Swap two variables/ public static void swap(int n1, int n2) f int temp n1; nl n2; n2 -temp; Swap the first two elements in the array/ public static void swapFirstTwoInArray (int[] array) f int temp array[0): array[0] array[i]; array[1] - temp
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
