| CSCI A201/A597 and I210Midterm Exam One Second Summer 2002 |
All correct
answers are worth exactly one point. Leaving a question unanswered will count
as a zero. There is no penalty for guessing. DO NOT MARK more than one answer
for each question.
Good luck and do well!
Write your name or username here:______________________
| 1. What is the output produced by the following three lines (when embedded in a complete program)? | |
int x, y; x = 2; y = 3; System.out.println(1 + "x" + y); |
|
| Note: To save space I wrote
| |
| 2. What is the output produced by the following three lines (when embedded in a complete program)? | |
|
|
| 3. What is the output produced by the following two lines (when embedded in a complete program)? | |
char a; a = 3 + 'B'; System.out.println(a); |
|
| 4. What is the output produced by the following program fragment (when embedded in a complete program)? Note that the indentation may or may not be right so please be careful. | |
|
|
| 5. What is the type of this expression: | |
"1" + 'a' |
|
| 6. What is the type of this expression: | |
1 == 3 |
|
| 7. What is the type of this expression: | |
1 / 2 |
|
| 8. What is the type of this expression: | |
"abc".length() |
|
| 9. What is the type of this expression: | |
"abc".length() == 3 |
|
| 10. What is the type of this expression: | |
"appearance".substring(2, 6) |
|
| 11. What is the type of this expression: | |
"abc".toUpperCase() |
|
| 12. What is the output produced by the following three lines (when embedded in a complete program)? | |
int a, b; a = 3; b = 5; System.out.println(b * (a / b) + a % b); |
|
| 13. What is the output produced by the following three lines (when embedded in a complete program)? | |
int a, b; a = 3; b = 5; System.out.println(b * a / b + a % b); |
|
| 14. What is the output produced by the following code when embedded in a complete program? (Note that the program may or may not be indented correctly so think about it carefully.) | |
|
|
| 15. What is the output produced by the following code when embedded in a complete program? (Note that the program may or may not be indented correctly so think about it carefully.) | |
|
|
| 16. What is the output produced by the following code when embedded in a complete program? (Note that the program may or may not be indented correctly so think about it carefully.) | |
|
|
| 17. What is the output produced by the following code when embedded in a complete program? (Note that the program may or may not be indented correctly so think about it carefully.) | |
|
|
| 18. What is the output produced by the following code when embedded in a complete program? (Note that the program may or may not be indented correctly so think about it carefully.) | |
|
|
| 19. What is the output produced by the following code when embedded in a complete program? | |
boolean x = false; if (true) System.out.print(10); else System.out.print(1); x = x || !x; if (x) System.out.print(0); else System.out.print(00); |
|
| 20. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 21. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 22. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 23. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 24. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 25. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 26. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 27. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 28. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 29. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 30. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 31. What is the output produced by the following code when embedded in a complete program? | |
|
|
32. Are these two code fragments equivalent (do they
always change x in the exact same way)?
| |||||
|
|
| ||||
For
the following 5 (five) exercises consider
the following method definitions:
public static int f(int x) {
return x + 1;
}
public static int g(int x) { return x + 2; }
public static int h(int x) { return x - 2; }
public static int k(int x) { return x - 1; }
33. What does g(2) evaluate to?
| |
| |
34. What does g(h(2)) evaluate to?
| |
| |
35. What does k(g(2) + h(2)) evaluate to?
| |
| |
36. What does f(0) + f(1) + f(2) evaluate to?
| |
| |
37. What does f(2) evaluate to?
| |
| |
38. "true" is an example of what kind of constant?
| |
| |
39. true is an example of what kind of constant?
| |
| |
40. Assume that x is an integer variable. Simplify
the following expression: | |
!((x >= 4) && (x <= 4)) |
|
Warning: Don't overlook the logical negation (bang!) at the front.
| 41. How many instance methods do you see defined below? | |
|
|
| 42. How many static methods do you see defined below? | |
|
|
| 43. How many instance variables do you see defined below? | |
|
|
| 44. How many instance variables do you see defined below? | |
|
|
| 45. How many instance variables do you see defined below? | |
|
|
| 46. How many local variables do you see defined below? | |
|
|
| 47. You compile and run this program. What is the output (or outcome)? | |
|
|
| 48. You compile and run this program. What is the output (or outcome)? | |
|
|
49. Which of the following expressions does NOT print a 4 (four)?
| |
| |
| Note: There are no typos! | |
| 50. What's the output produced by the following lines (when embedded in a complete program)? | |
String a = "blue"; String b = "berry"; System.out.println( "blueberry".substring(a.length(), b.length())); |
|
| 51. What gets printed when you compile and run the following program? | |
|
|
| There are no typos, so please don't rush! | |
| 52. What is the result of attempting to compile and run the following code? | |
|
|
A201/A597/I210 Midterm Exam Fri Jul 12 2002 in LH102