What is the result?

Given:

1. public static void main(String[] args) {
2. for (int i = 0; i <= 10; i++) {
3. if (i > 6) break;
4. }
5. System.out.println(i);
6. }

What is the result?

Given:

1. public static void main(String[] args) {
2. for (int i = 0; i <= 10; i++) {
3. if (i > 6) break;
4. }
5. System.out.println(i);
6. }

What is the result?

A.
6

B.
7

C.
10

D.
11

E.
Compilation fails.

F.
An exception is thrown at runtime.

Explanation:
Main.java:5: cannot find symbol
symbol : variable i
location: class Breaker
System.out.println(i);
^
1 error



Leave a Reply 1

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