What is the result?

Given:
<code>
public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println(“ii = “+ ii);
ii = ii +1;
}
</code>
What is the result?

Given:

public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println("ii = "+ ii);
ii = ii +1;
}

What is the result?

A.
ii = 0
ii = 2

B.
ii = 0
ii = 1
ii = 2
ii = 3

C.
ii =

D.
Compilation fails.



Leave a Reply 2

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


sully

sully

how do u get A
shouldn’t it be 1 and 3 as whats print out

the for loop iterates it to 1 and then prints out
iterates to 2, next loop brings it to 3 for print out

nisha

nisha

“For” loop increments value only at the end of the iteration.
The + in print is a concat operation. Notice the quotes