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