WorksheetsWhile Statements HW
Total questions: 6
Worksheet time: 6mins
Name
Class
Date
1.
What is the output?
int x = 1;
while( x < 5 )
x = x + 1;
System.out.print(x);
int x = 1;
while( x < 5 )
x = x + 1;
System.out.print(x);
a)
234
b)
2345
c)
1234
d)
12345
2.
What is the output?
int m = 2;
int total = 0;
while( m < 6 )
total = total + m;
m = m + 1;
System.out.print(total);
int m = 2;
int total = 0;
while( m < 6 )
total = total + m;
m = m + 1;
System.out.print(total);
a)
2
b)
14
c)
8
d)
10
3.
What is the output?
int x=1;
while(x<4)
out.print(x);
x++;
int x=1;
while(x<4)
out.print(x);
x++;
a)
1
b)
1234
c)
123
d)
1
2
3
2
3
4.
What is the output?
int z=2;
while(z<8)
z++;
out.print(z);
int z=2;
while(z<8)
z++;
out.print(z);
a)
2345678
b)
234567
c)
34567
d)
345678
5.
What is the output?
int y=2;
while(y<8)
out.print(y);
y++;
int y=2;
while(y<8)
out.print(y);
y++;
a)
234567
b)
34567
c)
2345678
d)
345678
6.
What is the output?
int a = 1;
int total = 0;
while( a < 5 )
total = total + a;
a++;
System.out.print(total);
int a = 1;
int total = 0;
while( a < 5 )
total = total + a;
a++;
System.out.print(total);
a)
10
b)
8
c)
15
d)
14
100 %
