AP Java Chapter 6 WS 5 Loops MC
AP Java Chapter 6 WS 5 Loops MC
1. The following code segment intends that a user will enter a list of
positive integers at the keyboard and terminate the list with a sentinel
value:
int value;
final int SENTINEL = -999;
while (value != SENTINEL)
{
// code to process the inputted value
value = <integer value inputted by user>
}
A. It returns the smallest common factor of x and y, that is, the smallest
positive integer divisor of both x and y.
B. It returns the greatest common factor of x and y, that is, the largest
integer divisor of both x and y.
C. It returns the least common multiple of x and y, that is, the smallest
integer that has both x and y as a factor.
D. It returns y raised to the x th power, that is y x.
E. It returns x raised to the y th power, that is x y.
A. I only
B. II only
C. III only
D. II and III only
E. I, II, and III
Which of the following replacements for <code segment> would cause the
method to work as intended?
I. for (int i = 0; i <= n; i++)
{
rem = n % 10;
revNum = revNum * 10 + rem;
n /= 10;
}
II.while (n != 0)
{
rem = n % 10;
revNum = revNum * 10 + rem;
n /= 10;
}
A. I only
B. II only
C. I and II only
D. II and III only
E. I and III only