SCJP Module-5 Question-7


 

SCJP Module-5 Question-7

The program given below will test your understanding of for loop and nested loop in Java.

The program given below will test your understanding of for loop and nested loop in Java.

Given a sample code:

1    public class Test {
2    public static void main(String args[]) {
3    int i, j, k;
4    for (i = 0; i < 4; i++) {
5    for (j = 1; j < 3; j++) {
6    for (k = 2; k < 3; k++) {
7    if ((i == j) && (j != k))
8    System.out.println(i);
       }}}
}}

What will be the result of above code ?

(1) 1
(2) 0
(3) 4
(4) The program compilation fails because of line number 2.

Answer:

(1)

Ads