![]() You can do it! | CSCI A201/A597/I210 Final Examination Summer II 2003
|
Good luck and do well!
1. Consider the following condition.
Which of the following represents a simplification of it?(x % 4 == 0 || (x % 100 == 0 && x % 400 == 0))
| |
| |
2. Consider the following condition.
Which of the following represents a simplification of it.! (a == ! false) | |
| |
3. Consider the following program fragment.
What value does y have at the end?int x = 12, y = 0; if (x < 10) if (x > 5) y = 1; else y = 2; | |
| |
4. Consider the following program fragment.
What value does y have at the end?int x = 8, y = 0; if (x < 6) { if (x > 5) y = 1; } else y = 2; | |
| |
5. Consider the following program fragment.
What value does y have at the end?int x = 36, y = 8; if (x < 10) { if (x > 5) y = 1; else y = 2; } | |
| |
6. Consider the following program fragment.
What value does y have at the end?int x = 8, y = 0; if (x < 10) ; if (x > 5) y = 1; else y = 2; | |
| |
7. How many question marks will be printed by the following code fragment?
for (int i = -10; i <= 10; i = i + 3) ; System.out.print("?"); | |
| |
8. How many question marks will be printed by the following code fragment?
for (int i = 7; i >= 0; i--) System.out.print("?"); | |
| |
9. Consider the following fragment. What does it print?
int x = 3, y = 11; x = x + y; x = x - y; y = x - y; System.out.println("(" + x + ", " + y + ")"); | |
| |
10. Consider the following fragment. What does it print?
int x = 11, y = 3; y = x - y; x = y + x; y = y - x; System.out.println("(" + x + ", " + y + ")"); | |
| |
11. Consider the following fragment. What does it print?
int[] v = new int[10]; for (int i = 0; i < 10; i++) v[i] = 2 * i; System.out.print(v[3] + v[1]) | |
| |
12. Consider the following fragment. What does it print?
int[] v = { 2, 4, 6, 8, 10, 12}, m = { 1, 3, 5, 7, 9, 11}; for (int i = 0, sum = 0; i < 10; i++) sum -= (m[i] - v[i]); System.out.print(sum) | |
| |
13. Consider the following program. What does it print?
int[] a = { 0, -1, 1, -2, 2, -3, 3}; int fun = a[a.length - 1]; for (int i = a.length - 1; i >= 0; i--) if (a[i] <= fun) fun = a[i]; System.out.println(fun); | |
| |
14. Consider the following program fragment.
What's need for the output to resemble anpublic class One { public static void main(String[] args) { int size = 10, nuf, fun; for (nuf = 0; nuf < size; nuf++) { for (fun = 0; fun < size; fun++) if ( fun == 0 || fun == size - 1 || __________________ ) System.out.print(" *"); else System.out.print(" "); System.out.println(); } } } N ?
| |
| |
15. Consider the following command line invocation:
Assume your program contains this line insidejava One Two Three Four Five What does this line print?
| |
| |
16. Consider the following code fragment, what does it print?
String plum = "nectarine"; System.out.println(plum.substring("plum".length(), "peach".length()); | |
| |
17. Consider
the following code fragment, what does it print?
String plum = "nectarine"; System.out.println((char)('A' + plum.length())); | |
| |
18. Consider the following code fragment, what does it print?
String plum = "nectarine"; System.out.println((char)('A' + "plum".length())); | |
| |
19. Does this source code compile?
class Momerath { } class Tove extends Momerath { } class Kroger { public static void main(String[] args) { Tove a = new Momerath(); } } | |
| |
20. Does this source code compile?
class Tove { } class Momerath extends Tove { } class Kroger { public static void main(String[] args) { Tove a = new Momerath(); } } | |
| |
21. Does this source code compile?
class Wabe { } class Tove extends Wabe { } class Momerath extends Tove { } class Kroger { public static void main(String[] args) { Wabe a = new Momerath(); } } | |
| |
22. Does this source code compile?
class Wabe { } class Tove extends Wabe { } class Momerath extends Tove { } class Kroger { public static void main(String[] args) { Tove a = new Wabe(); } } | |
| |
23. You compile and run this code, what is the output?
class One { int red; One() { this(10); } One (int blue) { red += blue; } int report() { System.out.println(red); } public static void main(String[] args) { One x = new One(20); x = new One(30); x = new One(); x.report(); } } | |
| |
24. If you
compile and run this code, what is the output?
class One { public static void main(String[] args) { int[][] a = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {6, 2, 7} }; System.out.println(a[a[1][0] - 1][0]); } } | |
| |
25. If you compile and run this code, what is the output?
class One { public static void main(String[] args) { int[] x = {1, 2, 3}; fun(x[0]); // focus here!! System.out.println(-x[0] + x[1] + x[2]); } public static void fun(int value) { value = value - 1; } } | |
| |
26. If you compile and run this code, what is the output?
class One { public static void main(String[] args) { int[] x = {1, 2, 3}; fun(x, 0); // focus here!! System.out.println(-x[0] + x[1] + x[2]); } public static void fun(int[] value, int index) { value[index] = value[index] - 1; } } | |
| |
27. What gets printed when you compile and run the following program?
class One { public static void main(String[] args) { System.out.println(one(one(two(one(two(1, 2), 1), 2), two(1, 2)), 1)); } public static int one(int b, int a) { return a + b; } public static int two(int b, int a) { return a - b; } } | |
| |
28. Assuming that the following program fragment is syntactically correct...
int[][] a = new int[10][10]; ... a[0][1] = fun(a[2], a[0][0]); | |
... select the correct header for method fun .
| |
29. Assuming
that the following program fragment is syntactically correct...
int[][] a = new int[10][10]; ... a[0] = fun(a[1][2], a); | |
... select the correct header for method fun .
| |
30. Assuming that the following program fragment is syntactically correct...
int[][] a = new int[10][10]; ... a = fun(a[1], a); | |
... select the correct header for method fun .
| |
31.
What is the result of attempting to compile and run this code?
class Alpha { public static void main(String[] args) { System.out.println("... will not run"); } public static void main() { System.out.println("... won't compile"); } } | |
| |
32.
What is the result of attempting to compile and run this code?
abstract class Alpha { int value; Alpha (int value) { this.value = value; System.out.println(value); } public static void main(String[] args) { Beta f = new Beta(2003); } } class Beta extends Alpha { Beta (int value) { super(value); } } | |
| |
33.
What is the result of attempting to compile and run this code?
class Alpha { public static void main(String[] args) { Alpha f = new Beta(); Alpha g = new Gamma(); System.out.println(f.test(g.test(3))); } int test(int i) { return (i + 2); } } class Beta extends Alpha { } class Gamma extends Beta { int test(int i) { return (i + 1); } } | |
| |
34.
What is the result of attempting to compile and run this code?
class Alpha { public void main(String[] args) { Beta f = new Beta(3); } Alpha (int i) { } } class Beta extends Alpha { Beta(int i) { } } | |
| |
35. What is the result of attempting to compile and run this code?
class Alpha { public static void main(String[] args) { Beta f = new Beta(); } } class Beta extends Alpha { } | |
| |
36.
What is the result of attempting to compile and run this code?
abstract class Alpha { abstract void complain(String s); } class Beta extends Alpha { void complain(String s) { System.out.println(s); } } class Tester { public static void main(String[] args) { Beta f = new Beta(); f.complain("There's a tomato in every automaton."); } } | |
| |
A201/A597 TTFN Exam Thu Aug 14 2003 in LH201