What is the output of the code snippet given below? int i; int j = 0; for (i = 0; i < 5; i++) { if (i % 2 == 0) { i = i + 2; j++; } else { i++; j = j + 2; } j++; } system.out.println("i=" + i + ", j=" + j);?

Respuesta :

Answer:

The output of this code is i=5, j=5.

Explanation:

In this code there are 2 integer variable is defined (i,j) that's data type is an integer. In the next line, there is a loop declare. This loop starts at 0 and ends from 4. In this loop, there is a conditional statement that starts with loop variable i. In this conditional, if (i%2==0 )then the value of i variable increment by two and the value of j variable increment by 1. else i variable value increment by 1 and j variable value increment by 2. In this loop when the i value is 3 it goes to the else part of the conditional statement. Then the end of conditional statement and loop. In the last j value is increased by 1. and print i and j value that is i=5, j=5.

Answer:

The output of this code is i=5, j=5.

Explanation:

In this code there are 2 integer variable is defined (i,j) that's data type is an integer. In the next line, there is a loop declare. This loop starts at 0 and ends from 4. In this loop, there is a conditional statement that starts with loop variable i. In this conditional, if (i%2==0 )then the value of i variable increment by two and the value of j variable increment by 1. else i variable value increment by 1 and j variable value increment by 2. In this loop when the i value is 3 it goes to the else part of the conditional statement. Then the end of conditional statement and loop. In the last j value is increased by 1. and print i and j value that is i=5, j=5.