?

Algorithms & Data Structures

Free Version

Upgrade subject to access all content

Moderate

Converting For Loops to While Loops

ALGOR-OXY8MN

Which of the following while loops will print the same values as this for loop?

for(int i = 0; i < 20; i += 2) {
    System.out.println(i);
}
A
int i = 0;
while(i <= 20) {
   System.out.println(i);
   i += 2;
}
B
int i = 0;
while(i < 20) {
    System.out.println(i);
    i += 2;
}
C
int i = 0;
while(i < 20) {
    System.out.println(i + 2);
}
D
int i = 0;
while(i < 20) {
    i += 2;
    System.out.println(i);
}