Oracle
1Z0-851 · Question #30
Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ", "); } } and the…
The correct answer is C. Compilation fails. See the full explanation below for the reasoning.
Question
Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ", "); } } and the invocation: test("four"); test("tee"); test("to"); What is the result?
Options
- Ar, t, t,
- Br, e, o,
- CCompilation fails.
- DAn exception is thrown at runtime.
How the community answered
(57 responses)- A4% (2)
- B7% (4)
- C72% (41)
- D18% (10)
Community Discussion
No community discussion yet for this question.