Unit 6: Array

Showing 18 of 18 questions

Q1
MULTIPLE_CHOICEEasy

What is the output of the following code?

Q2
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q3
MULTIPLE_CHOICEHard

What does the following method return when called with {4, 2, 7, 2, 4, 7, 4}?

Q4
MULTIPLE_CHOICEEasy

What happens when the following code is executed?

Q5
MULTIPLE_CHOICEMedium

After the following code executes, what are the values in arr?

Q6
MULTIPLE_CHOICEHard

What does the following method return when called with {3, 1, 4, 1, 5, 9, 2, 6}?

Q7
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q8
MULTIPLE_CHOICEEasy

What is the output of the following code?

Q9
MULTIPLE_CHOICEHard

What does the following method return for the array {1, 3, 5, 7, 9} and target 5?

Q10
MULTIPLE_CHOICEMedium

What is the output of the following code?

Q11
MULTIPLE_CHOICEEasy

What happens when you access arr[5] for an array of size 5?

Q12
MULTIPLE_CHOICEMedium

What does this code do?\nint max = arr[0];\nfor (int i = 1; i < arr.length; i++) if (arr[i] > max) max = arr[i];

Q13
MULTIPLE_CHOICEHard

After one complete pass of selection sort on {5, 3, 8, 1, 4}, the array becomes:

Q14
MULTIPLE_CHOICEMedium

Insertion sort works by:

Q15
MULTIPLE_CHOICEHard

In Java, arrays are passed to methods by:

Q16
MULTIPLE_CHOICEMedium

To swap arr[i] and arr[j], which approach is correct?

Q17
MULTIPLE_CHOICEHard

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?

Q18
MULTIPLE_CHOICEMedium

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