Professional Documents
Culture Documents
Sample Final Exam
Sample Final Exam
Putnam
NAME: ___________________________________________
Answer all questions on the test paper. This is a closed book exam. Show all of
your work. No calculators or any other electronic devices may be used during
the test. The test is 120 minutes long.
1. (20 pts) Write a complete java program that inputs four numbers x1, y1, x2, y2
and computes
The program should print the values of x1, y1, x2, y2 and the computed square
root.
3. (15 pts) Determine the results of the evaluation of the following expressions.
Show how Java parenthesizes the expression, show the value of the
expression and show the resulting data type. Assume that x, y and z are type
double and that x = 2.0, y = 33.0 and z = 5.0. Assume that a, b and c are type
int and that a = 2, b = 2, c = 5.
(int)(56.78*100)/100.0
( c == 5) || ( a > 2 ) && ( b
!=2)
45 + 43 % 5 * (23 * 3 % 2)
4. Given the following program:
boolean p, q, r;
A;
if (p)
{
B;
if (q) C;
else if (r) D;
if (p && q) E;
}
else if (q && r)
{
F;
if (!p) G;
if (!q) H;
}
if (r)
{
J;
if (p II q) K;
}
The public void addOneMinute() method adds one minute to the time while
maintaining the constraints. Note that adding one minute to 10:59 a.m. is not
10:60 a.m. it is 11:00 a.m. Adding one minute to 11:59 a.m. is 12:00 p.m, not
12:00 a.m.
}
public void addOneMinute()
{