JAVA programming language:
What is the output?
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 8; j++) {
if (j>= 2) {
break:
}
System.out.print("" + i + j + " ");
}
}
Select one:
a) 00 11 22 00 11 22
b) 00 01 10 11 20 21
c) 012 123 234
d) 000 001 100 110 200 210
In the given code, the inner loop will iterate only 2 times
for
outer loop. Third time break will terminate the loop.
The outer loop will iterate 3 times.
(a) 00 11 22 00 11 22
This option is incorrect as 00 is coming again but in the code the
outer loop
only runs in ascending order
(b) 00 01 10 11 20 21
This option is correct as the outer loop prints the first digit and
inner loop
prints the second digit of a combo.
0 and 1 from the inner loop will be printed for each 0,1 and 2 of the outer loop.
(c) 012 123 234
This is incorrect as three digits cannot be combined without space
in output.
(d) 000 001 100 110 200 210
This is incorrect as three digits cannot be combined without space
in output.
Therefore, the correct option is (b) 00 01 10 11 20 21
Get Answers For Free
Most questions answered within 1 hours.