What is the result?

Given:

1. public class Breaker {
2. static String o = “”;
3.
4. public static void main(String[] args) {
5. z: o = o + 2;
6. for (int x = 3; x < 8; x++) {
7. if (x == 4)
8. break;
9. if (x == 6)
10. break z;
11. o = o + x;
12. }
13. System.out.println(o);
14. }
15. }

What is the result?

Given:

1. public class Breaker {
2. static String o = “”;
3.
4. public static void main(String[] args) {
5. z: o = o + 2;
6. for (int x = 3; x < 8; x++) {
7. if (x == 4)
8. break;
9. if (x == 6)
10. break z;
11. o = o + x;
12. }
13. System.out.println(o);
14. }
15. }

What is the result?

A.
23

B.
234

C.
235

D.
2345

E.
2357

F.
23457

G.
Compilation fails.

Explanation:
Main.java:10: undefined label: z
break z;
^
1 error



Leave a Reply 1

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