0% found this document useful (0 votes)
36 views3 pages

Test Spring

These questions are about methods, loops, conditionals, and arrays in Java. The questions test understanding of concepts like recursion, loops, array traversal, and method calls. Correct answers would depend on tracing the logic and state changes within the provided code snippets.

Uploaded by

Congyao Zheng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Test Spring

These questions are about methods, loops, conditionals, and arrays in Java. The questions test understanding of concepts like recursion, loops, array traversal, and method calls. Correct answers would depend on tracing the logic and state changes within the provided code snippets.

Uploaded by

Congyao Zheng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

19.

If c and d are boolean variables, which of the answer


choices is NOT equivalent to the following expression?
(c && d) != (c || d)

a. (c && !d) || (!c && d)


b. (c || d) && (!c && !d)
c. (c || d) && (!c || !d)
d. (c || d) && !(c && d)
e. c != d

22. private static void f (int a, int b)


{
if (a / b != 0)
f (a / b, b);
System.out.print (a % b);
}

Given the method above, what is printed by the call f(4,2) ?


a.221
b.201
c.3
d.100
e.101

23. Given the method above, what is printed by the call f(5,2)
?
a.221
b.201
c.3
d.100
e.101

24. Given the method above, what is printed by the call f(3,7)
?
a.221
b.201
c.3
d.100
e.101

25. How many times will method go()be called given the call
check(10)?
private static void check (int n)
{
for (int i = 0 ; i < n ; i++)
for (int j = 0 ; j < n ; j++)
go (i * j);
}
a.100
b.55
c.45
d.90
e.54

26. Consider the following recursive method.


private static int mystery (int n)
{
if (n <= 1)
return 0;
else
return 1 + mystery (n / 2);
}
Assuming that k is a nonnegative integer and m=2k, what value
is returned as a result of the call mystery(m)?

(a)0
(b)k
(c)m
(d)m/2+1
(e)k/2+1

27. Consider the following method.


private static void doSome (int[] arr, int lim)
{
int v = 0;
int k = 0;
while (k < arr.length && arr [k] < lim)
{
if (arr [k] > v)
{
v = arr [k]; /* Statement S */
}
k++; /* Statement T */
}
}
Assume that doSome is called and executes without
error and arr contains only positive values. Which of
the following are possible combinations for the value
of lim, the number of times Statement S is executed,
and the number of times Statement T is executed?

Value Executions of Executions of


of Statement S Statement T
lim
I 5 0 5
II 7 4 9
III 3 5 2

(a) I only
(b) II only
(c) III only
(d) I and III only
(e) II and III only

You might also like