15-110 Sections M-Q / Fall 2009 / Quiz 1
(version A)
5 Parts / 25 Minutes
· Only write your final answer in the answer column. Place scratch work outside the answer boxes.
· All code examples compile and run without errors (except where explicitly noted otherwise in Part 5).
·
Unicode ‘A’ is 65, ‘a’ is 97,
and ‘0’ is 48.
1a. (10 pts) Writing Code |
Answer #1a |
|
1b. (10 pts) Writing Code |
Answer #1b |
|
2. (20 pts)
Tracing System.out.println(99/x + 99.0/x); System.out.println(x/99); System.out.println(4+99%x); x++; y*=2;
System.out.println(x%12+y); |
|
Answer #2 |
3. (20 pts)
Tracing
int x = 10; } |
|
Answer #3 |
4a.
(10 pts) Mystery Method |
Answer #4a |
|
|
4b. (10 pts)
Mystery Method assert((x >= 0) && (y >= 0)); double d1 = Math.sqrt(x); double d2 = Math.pow(y, 2); return (Math.abs(d1 - d2) < 0.000001); } |
Answer #4b |
|
5. (20 pts)
Short Answers (Answer in 5
words or less.) 2: int x = Integer.parseInt("uh oh"); 3: double d = x; 4: char c = 'a'+x; 5: String s = d + "" + c;
6: } 2: int x = 5, y = 11; 3: String s = "ack"; 4: boolean b = ((x > y/2.0) && 5: (x/Integer.parseInt(s)==3)); 6: x %= x/y; 7: System.out.println("x = " + x); 8: }
2: int root = (int)Math.pow(9, 1/2);
3:
System.out.println("Square root of 9 = " + 5: }
5g For y>0, if (x%y) > x, then we know that x __________. |
Answer #5 5a.
5c.
5d.
5e.
5f.
5g. |