Java Topic Practice
Sorting and Efficiency
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
For practice use only.
Sorting and Efficiency MCQ Practice
Sorting and Efficiency Java practice with 15 questions, code tracing, and a worked explanation for every answer.
Question 1 of 15
Answered 0 of 15
Choose one answer.
Code Tracing 01 - Sorting and Efficiency: track the final printed value.
int[] data = {4, 9, 2, 7, 5, 1};
int swaps = 0;
for (int i = 0; i < data.length - 1; i++) {
for (int j = 0; j < data.length - 1 - i; j++) {
if (data[j] > data[j + 1]) {
int t = data[j];
data[j] = data[j + 1];
data[j + 1] = t;
swaps++;
}
}
}
System.out.print(swaps);