0%
0 / 15 answered
while Loops() Practice Test
•15 QuestionsQuestion
1 / 15
Q1
Analyze the following code.
// Scenario: search an array until a target is found
int[] data = {2, 4, 6, 8, 10};
int index = 0; // initialization
while (index < data.length && data<u>index</u> != 8) { // stop when found
index++; // update
}
System.out.println(index);
What will be the output of the given code?
Analyze the following code.
// Scenario: search an array until a target is found
int[] data = {2, 4, 6, 8, 10};
int index = 0; // initialization
while (index < data.length && data<u>index</u> != 8) { // stop when found
index++; // update
}
System.out.println(index);
What will be the output of the given code?