Sample
Final Exam Solutions
I
have provided what goes into the blanks for the fill in the blank problems.
Question 1
Segment
1: 15
Segment
2: 3
Segment
3:
-
-
*
-
-
*
-
*
-
-
*
-
*
-
-
*
-
*
-
Question 2
(a)
in.readInt()
in.readInt()
(previous
> 0) || (current > 0)
previous
= current
current
= in.readInt()
previous
+ " " + current
(b)
(previous
<= 0) && (current <= 0)
Question 3
2
(p
% d) != 0
d
+ 1
d
== p
p
+ "is prime"
p
+ "is not prime"
Question 4
(reflect)
start
< end
A[start]
A[start]
= A[end]
A[end]
= temp
(swap)
reflect(A,
0, k-1);
reflect(A,
k, A.length - 1);
reflect(A,
0, A.length - 1);
Question 5
((r
< map.length) && (r >= 0) &&
(c < map[r].length) && (c >= 0)
&&
(map[r][c] == (val + 1)))
Question 6
M.length
M[0].length
for (col = 0; col < width; col++)
{
for (row
= col; row < height; row++)
sum =
sum+M[row][col];
}
return sum;
Question 7
1c,
2c, 3i, 4c, 5i, 6c, 7i, 8c, 9c, 10i, 11c, 12c, 13c, 14i, 15c
Question 8
uniInteract(p);
p.unIInteract(this);
enemy
= p
class
WackyPerson extends Person {
public WackyPerson (String n) {
super(n,
2000);
enemy
= this;
}
public void uniInteract(Person q) {
for
(int i = 1; i <= 100, i++)
super.uniInteract(q);
}
}
Question 9
(a)
x
= size(M)
N
= M(2:x(1) - 1, 2:x(2) - 1)
(b)
function
n = COUNT(V, X)
y = (V==X)
n = sum(y)
(c)
COUNT(N(:,
2), 99)