What will be the value of the variable count after executing of this code?

int count = 1, i = 0;
do {
    count *= ++i;
    if (count > 5) break;
} while (i <= 4);
Explanation
iteration 0: i = 0 + 1 = 1; count = 1 * 1 = 1;
iteration 1: i = 1 + 1 = 2; count = 1 * 2 = 2;
iteration 2: i = 2 + 1 = 3; count = 2 * 3 = 6;
(6 > 5) breaks the loop

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes