Unit 6: Array
Showing 18 of 18 questions
What is the output of the following code?
What is the output of the following code?
What does the following method return when called with {4, 2, 7, 2, 4, 7, 4}?
What happens when the following code is executed?
After the following code executes, what are the values in arr?
What does the following method return when called with {3, 1, 4, 1, 5, 9, 2, 6}?
What is the output of the following code?
What is the output of the following code?
What does the following method return for the array {1, 3, 5, 7, 9} and target 5?
What is the output of the following code?
What happens when you access arr[5] for an array of size 5?
What does this code do?\nint max = arr[0];\nfor (int i = 1; i < arr.length; i++) if (arr[i] > max) max = arr[i];
After one complete pass of selection sort on {5, 3, 8, 1, 4}, the array becomes:
Insertion sort works by:
In Java, arrays are passed to methods by:
To swap arr[i] and arr[j], which approach is correct?
Consider the following method. \npublic static int[] mystery(int[] arr) { int[] result = new int[arr.length]; for (int i = 0; i < arr.length; i++) { result[arr.length - 1 - i] = arr[i]; } return result; } \nIf int[] a = {2, 4, 6, 8, 10}, what does mystery(a) return?
What is the output? int[] arr = {5, 3, 8, 1, 9, 2}; for (int i = 0; i < arr.length - 1; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; } } System.out.println(arr[arr.length - 1]);
Advertisement