PAPER 2026 COMPLETE SOLUTIONS AND
CORRECT ANSWERS GRADED A+
⩥ 44) Which of the following is considered a loop with a bound that
could be problematic?
a) for (i = 1; i != n; i++)
b) for (years = n; years < 0; years--)
c) for (i = 1; i <= n; i++)
d) for (int i = 1; i <= 10; i++). Answer: Answer: a) for (i = 1; i != n; i++)
⩥ 45) In the __________ loop header, you can include multiple update
expressions, separated by commas, but it is not recommended.
a) do
b) while
c) for
d) do. Answer: Answer: b) while
⩥ 46) What values does counter variable i assume when this loop
executes?
,for (int i = 20; i >= 2; i = i - 6)
{
System.out.print(i + ",");
}
a) 20, 14, 8, 2
b) 20, 14, 8, 2, -4
c) 20, 14, 8
d) 14, 8, 2. Answer: Answer: b) 20, 14, 8, 2, -4
⩥ 47) Insert a statement that will correctly terminate this loop when the
end of input is reached.
boolean done = false;
while (!done)
{
String input = in.next();
if (input.equalsIgnoreCase("Q"))
{
__________
}
,else
{
double x = Double.parseDouble(input);
data.add(x);
}
}
a) stop;
b) done = 1;
c) exit;
d) done = true;. Answer: Answer: d) done = true;
⩥ 48) What is the output of the code snippet given below?
String s = "abcdefghijkl";
int i = 1;
do
{
if (i > 2)
{
System.out.print(s.substring (1, i));
}
, i++;
}
while (i < 5);
a) abcd
b) bcde
c) bcbcd
d) cdef. Answer: Answer: c) bcbcd
⩥ 49) What is the output of this code snippet if the user enters the
numbers 1 2 3 4 -1 5?
double total = 0;
boolean hasValidNumber = true;
Scanner in = new Scanner(System.in);
while (in.hasNextDouble() && hasValidNumber)
{
double input = in.nextDouble();
if (input < 0)
{
hasValidNumber = false;
}