What will be the output of the program? int i = 1, j = 10; do { if(i > j) { break; } j--; } while (++i < 5); system.out.println("i = " + i + " and j = " + j);
a. i = 6 and j = 5
b. i = 5 and j = 5
c. i = 6 and j = 4
d. i = 5 and j =6?
Answers
Answered by
3
Hey Friend, Here's your answer
This loop is a do-while loop, which always executes the code block within the block at least once, due to the testing condition being at the end of the loop, rather than at the beginning. This particular loop is exited prematurely if i becomes greater than j.
The order is, test i against j, if bigger, it breaks from the loop, decrements j by one, and then tests the loop condition, where a pre-incremented by one i is tested for being lower than 5. The test is at the end of the loop, so ican reach the value of 5 before it fails. So it goes, start:
1, 10
2, 9
3, 8
4, 7
5, 6 loop condition fails.
So Answer Is Option D
Hope it helps
Thanks
Mark As Brainliest if you liked to
This loop is a do-while loop, which always executes the code block within the block at least once, due to the testing condition being at the end of the loop, rather than at the beginning. This particular loop is exited prematurely if i becomes greater than j.
The order is, test i against j, if bigger, it breaks from the loop, decrements j by one, and then tests the loop condition, where a pre-incremented by one i is tested for being lower than 5. The test is at the end of the loop, so ican reach the value of 5 before it fails. So it goes, start:
1, 10
2, 9
3, 8
4, 7
5, 6 loop condition fails.
So Answer Is Option D
Hope it helps
Thanks
Mark As Brainliest if you liked to
Similar questions
Science,
8 months ago
Hindi,
8 months ago
Hindi,
8 months ago
Accountancy,
1 year ago
Chemistry,
1 year ago