| CSCI A201/A597Midterm Exam One Spring 2000 The correct answers are in underlined blue.
|
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)? | |
|
|
| 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)? | |
int a; a = 'E' - '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 output produced by the following three lines (when embedded in a complete program)? | |
int a, b; a = 12; b = 5; System.out.println(b * (a / b) + a % b); |
|
| 7. What is the output produced by the following three lines (when embedded in a complete program)? | |
int a, b; a = 12; b = 5; System.out.println(b * a / b + a % b); |
|
| 8. 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.) | |
int x = 3; if (2 > x) System.out.print(1); else System.out.print(2); if (x < 2) System.out.println(3); System.out.print(4); |
|
| 9. 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.) | |
|
|
| 10. 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.) | |
int x = 14; while (x < 15) x = x + 1; System.out.print(x); |
|
| 11. 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.) | |
|
|
| 12. 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.) | |
|
|
| 13. What is the output produced by the following code when embedded in a complete program? | |
boolean x; if (true) System.out.print(0); else System.out.print(1); x = (1 < 2) && (4 < 3); if (x) System.out.print(2); else System.out.print(3); |
|
| 14. What is the output produced by the following code when embedded in a complete program? | |
boolean x = false; if (true) System.out.print(0); else System.out.print(1); x = x || !x; if (x) System.out.print(2); else System.out.print(3); |
|
| 15. What is the output produced by the following code when embedded in a complete program? | |
int x = 3; if (x > 0) System.out.print(x + 1); else if (x > 1) System.out.print(x); else if (x > 2) System.out.print(x - 1); else if (x > 3) System.out.print(2 * x); else System.out.print(x * x); |
|
16. What is the output produced by the following code when
embedded in a complete program? (The code is identical to the
one in problem 15 above, except two else's have
been removed). As always, please be careful about indentation
in the resulting program.
| |
int x = 3; if (x > 0) System.out.print(x + 1); |
|
| 17. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 18. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 19. What is the output produced by the following code when embedded in a complete program? | |
|
|
| 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. Is this an example of an infinite loop? | |
|
|
| 23. Is this an example of an infinite loop? | |
|
|
| 24. Is this an example of an infinite loop? | |
|
|
| 25. Is this an example of an infinite loop? | |
|
|
| 26. Is this an example of an infinite loop? | |
|
|
| 27. What is the output produced by the following code when embedded in a complete program? (Note that the fragment may or may not be indented correctly so please think about it carefully.) | |
|
|
| 28. What is the output produced by the following code when embedded in a complete program? (Note that the fragment may or may not be indented correctly so please think about it carefully.) | |
|
|
| 29. What is the output produced by the following code when embedded in a complete program? (Note that the fragment may or may not be indented correctly so please think about it carefully.) | |
|
|
| 30. What is the output produced by the following code when embedded in a complete program? (Note that the fragment may or may not be indented correctly so please think about it carefully.) | |
|
|
31. Is this an example of an infinite loop?
|
|
32. Is this an example of an infinite loop?
|
|
| 33. Consider the following program, it prints out a pattern. Which of the following letter patterns is closest in shape to the pattern that the program produces? | |
|
|
| 34. Consider the following program, it prints out a pattern. Which of the following letter patterns is closest in shape to the pattern that the program produces? | |
|
|
35. Assume the code fragment below. Does anything change in the way
z gets updated if we remove the else keyword?
| |
if (x > y) z = z + 1; else if (x <= y) z = z + 2; |
|
36. Assume the code fragment below. Does anything change in the way
z gets updated if we remove the else keyword?
| |
if (! (x > y)) z = z + 2; else z = z + 1; |
|
37. Are these two code fragments equivalent (in terms of the value
of x at the end of the fragment, when the fragment gets
executed)?
| |||||
|
| ||||
Thu Mar 2 16:00:00 EST 2000 (A201, Rawles Hall 100)