What is the result?

Given:

11. public static void test(String str) {
12. int check = 4;
13. if (check = str.length()) {
14. System.out.print(str.charAt(check -= 1) +”, “);
15. } else {
16. System.out.print(str.charAt(0) + “, “);
17. }
18. } and the invocation:
21. test(“four”);
22. test(“tee”);
23. test(“to”);

What is the result?

Given:

11. public static void test(String str) {
12. int check = 4;
13. if (check = str.length()) {
14. System.out.print(str.charAt(check -= 1) +”, “);
15. } else {
16. System.out.print(str.charAt(0) + “, “);
17. }
18. } and the invocation:
21. test(“four”);
22. test(“tee”);
23. test(“to”);

What is the result?

A.
r, t, t,

B.
r, e, o,

C.
Compilation fails.

D.
An exception is thrown at runtime.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Matti

Matti

C is correct. Line 13