exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 18 discussion

Actual exam question from Oracle's 1z0-808
Question #: 18
Topic #: 1
[All 1z0-808 Questions]

Given the code fragment:

Which code fragment prints red:blue:small:medium?
A.

B.

C.

D.

Show Suggested Answer Hide Answer
Suggested Answer: D

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
RoxyFoxy
Highly Voted 2 years, 4 months ago
If D: ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2! the correct answer is C!
upvoted 16 times
...
MPignaProTech
Most Recent 3 months ago
C is the correct answer
upvoted 2 times
...
z24134
1 year, 2 months ago
C is correct
upvoted 2 times
...
DarGrin
1 year, 3 months ago
C is the correct answer!
upvoted 2 times
...
duydn
1 year, 4 months ago
C is the correct one!
upvoted 2 times
...
Sreeni_A
1 year, 5 months ago
Correct option is C
upvoted 2 times
...
Vicky_65
1 year, 9 months ago
C is the correct one
upvoted 4 times
...
[Removed]
2 years, 1 month ago
Answer is C class HelloWorld { public static void main(String[] args) { String shirts[][] = new String[2][2]; //shirts[3][1] = "red"; //java.lang.ArrayIndexOutOfBoundsException shirts[0][0] = "red"; shirts[0][1] = "blue"; shirts[1][0] = "small"; shirts[1][1] = "medium"; for(String[] c : shirts){ //red:blue:small:medium: for(String s : c){ System.out.println(s + ":"); } } // for(int index = 0; index <= 2;){ //red: blue: java.lang.ArrayIndexOutOfBoundsException // for(int idx=0; idx<=2;){ // System.out.println(shirts[index][idx] + ":"); // idx++; // } // index++; // } } }
upvoted 3 times
...
willokans
2 years, 1 month ago
C is the answer for me
upvoted 3 times
...
anmoldev2java
2 years, 1 month ago
c is answer
upvoted 3 times
...
amigo31
2 years, 1 month ago
ANSWER IS C!
upvoted 4 times
...
morgan3987
2 years, 2 months ago
correct answer:C
upvoted 2 times
...
carloswork
2 years, 2 months ago
Source code.
upvoted 1 times
carloswork
2 years, 2 months ago
public static void main(String[] args) { String shirts[][] = new String[2][2]; shirts[0][0] = "red"; shirts[0][1] = "blue"; shirts[1][0] = "small"; shirts[1][1] = "medium"; /* A for (int index = 1; index < 2 ; index++) { for (int idx = 1; idx < index ; idx++) { System.out.print(shirts[index][idx] + ":" ); } } */ /* B for (int index = 0; index < 2 ; ++index) { for (int idx = 0; idx < index ; ++idx) { System.out.print(shirts[index][idx] + ":" ); } } */
upvoted 1 times
carloswork
2 years, 2 months ago
/* C */ for (String [] c : shirts) { for (String s : c) { System.out.print(s + ":"); } } /* D System.out.println(); for (int index = 0; index <= 2; ) { for (int idx = 0; idx <= 2; ) { System.out.print(shirts[index][idx] + ":" ); idx++; } index++; } */ }
upvoted 1 times
...
...
...
carloswork
2 years, 2 months ago
Tested, answer is only C. A and B, didnt print anything. D throws Exception (ArrayIndexOutOfBoundsException).
upvoted 2 times
carloswork
2 years, 2 months ago
Rewriting, A didn't print anything. B prints only "small:"
upvoted 2 times
...
...
hhuo
2 years, 3 months ago
Could anyone explain why B is not correct? I tested it, and it showed the exactly same result as C (red:blue:small:medium:).
upvoted 1 times
carloswork
2 years, 2 months ago
For me, B option returned only "small:"
upvoted 2 times
...
anmoldev2java
2 years, 2 months ago
for the first comparison where index = 0 and idx = 0 the condition idx < index will fail iteself.
upvoted 1 times
...
...
wk8b
2 years, 3 months ago
only C D is incorrect: red:blue:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago