2022 FINAL PAPER 2026 COMPLETE
SOLUTIONS AND CORRECT ANSWERS
GRADED A+
⩥ 22) What will be the output of the following code snippet?
boolean token = false;
while (token)
{
System.out.println("Hello");
}
a) "Hello" will be displayed infinite times.
b) No output because of compilation error.
c) No output after successful compilation.
d) "Hello" will be displayed only once. Answer: Answer: c) No output
after successful compilation.
⩥ 23) What will be the output of the following code snippet?
boolean token = false;
,do
{
System.out.println("Hello");
}
while (token);
a) "Hello" will be displayed infinite times.
b) No output because of compilation error.
c) No output after successful compilation.
d) "Hello" will be displayed only once.. Answer: Answer: d) "Hello" will
be displayed only once.
⩥ 24) What is the output of the following code snippet?
int i = 1;
while (i <= 10)
{
System.out.println("Inside the while loop");
i = i + 10;
}
a) No output because of compilation error.
,b) "Inside the while loop" will be displayed 10 times.
c) No output after successful compilation.
d) "Inside the while loop" will be displayed only once.. Answer: Answer:
d) "Inside the while loop" will be displayed only once.
⩥ 25) What is the outcome of the following code snippet?
boolean val1 = true;
boolean val2 = false;
while (val1)
{
if (val1)
{
System.out.println("Hello");
}
val1 = val2;
}
a) No output will be displayed because of compilation error.
b) "Hello" will be displayed only once.
c) "Hello" will be displayed infinite times.
d) No output will be displayed even after successful compilation of the
code snippet.. Answer: Answer:b) "Hello" will be displayed only once.
, ⩥ 26) How many times does the code snippet below display "Hello"?
int i = 0;
while (i != 15)
{
System.out.println("Hello");
i++;
}
a) Infinite times
b) 14 times
c) 15 times
d) 16 times. Answer: Answer: c) 15 times
⩥ 27) How many times does the following loop execute?
int upperCaseLetters = 0;
String str = "abcdEfghI";
boolean found = false;
for (int i = 0; i < str.length() && !found; i++)
{