Oracle
1Z0-803 · Question #244
Given the code fragment: String[] cartoons = {"tom","jerry","micky","tom"}; int counter =0; if ("tom".equals(cartoons[0])) { counter++; } else if ("tom".equals(cartoons[1])) { counter++; } else if ("t
The correct answer is A. 1. Counter++ will be executed only once because of the else if constructs.
Creating and Using Arrays
Question
Given the code fragment:
String[] cartoons = {"tom","jerry","micky","tom"}; int counter =0; if ("tom".equals(cartoons[0])) { counter++; } else if ("tom".equals(cartoons[1])) { counter++; } else if ("tom".equals(cartoons[2])) { counter++; } else if ("tom".equals(cartoons[3])) { counter++; } System.out.print(counter); What is the result?
Options
- A1
- B2
- C4
- D0
How the community answered
(35 responses)- A94% (33)
- B3% (1)
- D3% (1)
Explanation
Counter++ will be executed only once because of the else if constructs.
Topics
#arrays#string comparison#conditional statements#array indexing
Community Discussion
No community discussion yet for this question.