CS110 Practice Quiz 8
More looping structures
Choose the best alternative:
The
do/while
loop breaks when the boolean test condition is FALSE.
True
False
The
do/while
loop is a post-test loop.
True
False
The
while
loop is known as a
post-test
loop.
True
False
The
while
loop will always execute at least once. (A
one-trip
loop.)
True
False
.
The
do/while
loop will always execute at least once. (A
one-trip
loop.)
True
False
What output is produced by the segment of code shown below:
int i = 1;
while (i <= 5)
{ System.out.print('A');
i++;
}
The segment of code below will result in
AAA
an infinite loop
.
int i = 0;
while (i <= 2)
{ System.out.print('A'); }
What output is produced by the segment of code shown below:
static final int MAX = 4; //DECLARED GLOBAL
int f = 3;
while (f > MAX)
f = f - 2;
System.out.print(f) ;
What output is produced by the segment of code shown below:
static final int MAX = 4; //DECLARED GLOBAL
int f = 3;
do
f -= 2;
while (f > MAX);
System.out.print(f);
The output produced by the segment of code shown below is
0123
an infinite loop.
.
int x = 3;
do
System.out.print(x);
while (x >=3);
What output is produced by the segment of code shown below:
char c = 'a';
while (c <= 'f')
{ c += 2;
System.out.print(c);
}
What output is produced by the segment of code shown below:
int i = 1;
do
{ i++;
System.out.print(i);
i++;
}
while (i <= 10);
Answers
false.
true.
false. The only post-test loop is the do..while loop.
false. The while loop is a zero-trip loop.
true. The do..while loop is a post-test loop and will execute at least once.
AAAAA
An infinite loop.
3. NOTE: The loop boolean condition was false at the start.
1
an infinite loop.
ceg
246810