Check Your Understanding of While Loops With These Problems
Check Your Understanding of While Loops With These Problems
15
8. int x = 10;
while (x <= 20)
{
x += 2;
out.print(x + “ “);
}
12 14 16 18 20
9. int a = 1, b = 10;
while (a < b)
{
out.println(a + “ “ + b);
a++;
b--;
}
1 102 93 84 75 6
11. int a = 0;
int b = 10;
while (a < 50)
{
a += b;
b +=a;
out.println(a + " " + b);
}
10 2030 5080 130
12. int x = 0;
int y = 1;
while (x < 6)
{
y = y * 2;
x++;
} out.println(“x = “ + x); out.println(“y = “ + y);
x=6
y = 64