CSCI 121 Exam 1 Answers
|
1 |
There are 8 bits in a byte |
|
2 |
256 (28) different numbers may be represented using one byte |
|
3 |
getHeight returns the number of rows in a Picture object |
|
4 |
False |
|
5 |
True |
|
6a |
Subscripts of arr range from 0 to 6 |
|
6b |
The value of arr.length is 7 (the number of elements in arr) |
|
6c |
The value of arr[3] is 4 |
|
7 |
int, double, char, boolean, and float are Java primitive types |
|
8 |
t.penDown() will cause the Turtle to draw when it is moved |
|
9 |
p.show() causes a Picture p to display itself |
|
10 |
|
|
11 |
'a' is a valid char literal |
|
12 |
"I" and "I am" are both valid String literals |
|
13 |
The loop will be executed for the values of index ranging from 1 through 9. Therefore, “Thirteen” is printed 9 times |
|
14 |
False, since Java is a case-sensitive language |
|
15 |
The reserved word static is used to indicate class methods in Java |
|
16 |
31 % 4 = 3 (the operator % returns the remainder) |
|
17 |
31 / 4 = 7 (the integer quotient) |
|
18 |
31 / 4.0 = 7.75 |
|
19 |
3 + 4 * 5 = 23 (multiplication is done before addition) |
|
20 |
True—methods may be defined only within a class declaration |
|
21 |
Sets the color of the pixel in column 30, row 50 to the color green |
|
22 |
Since s is null, the value null is printed |
|
23 |
turtle1.turn(-65); |
|
24 |
for(int index =
47; index <= 96; index++) |
|
25 |
for (Pixel p :
pixels) |
|
26 |
int ndx = 0; int blue = pixels[ndx].getBlue(); |
|
27a |
public
MyPicture(String fileName) |
|
27b |
public
MyPicture(int columns, int rows) |
|
27c |
public void
grayscale() int blue = p.getBlue(); p.setRed(gray); p.setGreen(gray); or, using nested loops: int blue = p.getBlue(); p.setColor(new Color(gray, gray,
gray)); |
|
28 |
public void
shiftColors(int x1, int y1, int x2, int y2) int green = p.getGreen(); int blue = p.getBlue(); p.setColor(new Color(green, blue,
red)); } |
|
29 |
When
outer = 1, the inner loop executes 1 time (inner = 0) When
outer = 3, the inner loop executes 3 times (inner = 0, 1, 2) When
outer = 4, the inner loop executes 4 times (inner = 0, 1, 2, 3) Thus,
“twenty nine” is printed 1 + 2 + 3 +
4 = 10 times |