| 1. | Given:
class Hexy { public static void main(String[] args) { Integer i = 42; String s = (i<40)?"life":(i>50)?"universe":"everything"; System.out.println(s); } } What is the result?
| | ||||||||||||
| 2. | Given:
1. class Example { 2. public static void main(String[] args) { 3. Short s = 15; 4. Boolean b; 5. // insert code here 6. } 7. } Which, inserted independently at line 5, will compile? (Choose all that apply.)
| | ||||||||||||
| 3. | Given:
1. class Comp2 { 2. public static void main(String[] args) { 3. float f1 = 2.3f; 4. float[][] f2 = {{42.Of}, {l.7f, 2.3f}, {2.6f, 2.7f}}; 5. float[] f3 = {2.7f}; 6. Long x = 42L; 7. // insert code here 8. System.out.println("true"); 9. } 10. } And the following five code fragments:
F1. if (f1 == f2) F2. if (f1 == f2[2][1]) F3. if (x == f2[0][0]) F4. if (f1 == f2 [1,1] ) F5. if (f3 == f2 [2] ) What is true?
| | ||||||||||||
| 4. | Given:
class Fork { public static void main(String[] args) { if(args.length == 1 | args[1] .equals("test")) { System.out.println ("test case"); } else { System.out.println("production " + args[0]) ; } } } And the command-line invocation:
java Fork live2 What is the result?
| | ||||||||||||
| 5. | Given:
class Foozit { public static void main(String[] args) { Integer x = 0; Integer y = 0; for(Short z = 0; z < 5; z++) if((++x > 2) || (++y > 2)) X++ ; System.out.println (x + " " + y); } } What is the result?
| | ||||||||||||
| 6. | Given:
class Titanic { public static void main(String[] args) { Boolean bl = true; boolean b2 = false; boolean b3 = true; if((bl & b2) | (b2 & b3) & b3) System.out.print("alpha "); if((bl = false) | (b1 & b3) | (bl | b2)) System.out.print("beta "}; } } What is the result?
| | ||||||||||||
| 7. | Given:
class Feline { public static void main(String[] args) { Long x = 42L; Long y = 44L; System.out.print (" " + 7 + 2 + " ") ; System.out.print(foo () + x + 5 + " "); System.out.println(x + y + foo()); } static String foo() { return "foo"; } } What is the result?
| | ||||||||||||
| 8. | Place the fragments into the code to produce the output 33. Note, you must use each fragment exactly once. CODE:
class Incr { public static void main(String[] args) { Integer x = 7; int y = 2 ; X ___ ___; ___ ___ ___; ___ ___ ___; ___ ___ ___; System.out.println(x); } } FRAGMENTS:
| | ||||||||||||
| 9. | Given:
1. class Maybe { 2. public static void main(String[] args) { 3. boolean bl = true; 4. boolean b2 = false; 5. System.out.print(!false ^ false); 6. System.out.print(" " + (!b1 & (b2 = true))); 7. System.out.println(" " + (b2 ^ b1)); 8. } 9. } Which are true?
| | ||||||||||||
| 10. | Given:
class Sixties { public static void main(String[] args) { int x = 5; int y = 7 ; System.out.print(((y * 2) % x)); System.out.print(" " + (y % x)); } } What is the result?
| |
Answers
| 1. |
| ||||
| 2. |
| ||||
| 3. |
| ||||
| 4. |
| ||||
| 5. |
| ||||
| 6. |
| ||||
| 7. |
| ||||
| 8. |
class Incr{ public static void main(String[] args){ Integer.x = 7; int Y = 2; x *_ X; Y *= Y; Y = Y; x -= Y; System.out.println(x); } } Yeah, we know it's kind of puzzle-y, but you might encounter something like it on the real exam. (Objective 7.6) | ||||
| 9. |
| ||||
| 10. |
|