Oracle
1Z0-803 · Question #270
Given the code fragment: public class Test { public static void main(String[] args) { boolean isChecked = false; int arry[] = {1,3,5,7,8,9}; int index = arry.length; while ( <code1> ) { if (arry[index
The correct answer is A. Replacing <code1> with index > 0 and replacing <code2> with index--;. Note: Code in B (code2 is --index;). also works fine.
Using Loop Constructs
Question
Given the code fragment:
public class Test { public static void main(String[] args) { boolean isChecked = false; int arry[] = {1,3,5,7,8,9}; int index = arry.length; while ( <code1> ) { if (arry[index-1] % 2 ==0) { isChecked = true; } <code2> } System.out.print(arry(index]+", "+isChecked)); } } Which set of changes enable the code to print 1, true?
Options
- AReplacing <code1> with index > 0 and replacing <code2> with index--;
- BReplacing <code1> with index > 0 and replacing <code2> with --index;
- CReplacing <code1> with index > 5 and replacing <code2> with --index ;
- DReplacing <code1> with index and replacing <code2> with --index ;
How the community answered
(27 responses)- A74% (20)
- B4% (1)
- C7% (2)
- D15% (4)
Explanation
Note: Code in B (code2 is --index;). also works fine.
Topics
#While loop#Array indexing#Loop control#Conditional logic
Community Discussion
No community discussion yet for this question.