public class Foo {
public static void main(String[] args) {
for (var i = 0; i < 10; i++) {
switch (i % 5) {
case 2:
i *= 2 * i;
break;
case 3:
i++;
break;
case 1:
case 4:
i++;
continue;
default:
break;
}
System.out.print(i + " ");
i++;
}
}
}
// Result:
// 0 8
i=0 -> 0%5 is 0 so we go to default and break, then print 0 and increment it, so the next iteration will have i = 2.
I=2 -> 2%5 is 2 so we double I then break from the loop with I = 4 print 4, increment to 5 and continue.
I=6 -> 6%5 is 1 so we just increment and continue (go to the next iteration)
I=8 -> 8%5 is 3 so we just increment to 9 and break, print 9 then increment and reach 10 which is the end.
So the answer is D.
This section is not available anymore. Please use the main Exam Page.1z0-819 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
APJ1
1 year agojames2033
1 year, 2 months agoLebannin
1 year, 5 months agoStavok
1 year, 7 months agoAlanRM
1 year, 9 months agopikosss
1 year, 10 months agoAnkit1010
2 years ago