Statistics:
(including the 2-point curve) mean 22.615 (804.000/39) stddev 5.246 median 22.000 midrange 19.750-26.250 # avg 1 7.26 / 10 2 2.33 / 5 3 10.92 / 15 + 2-point curve
[10 pts] Suppose we have the class defined as below.
class C {
static int x = 0;
int y;
C() {
y = 0;
}
void incrX() {
x++;
IO.println(x);
}
void incrY() {
y++;
IO.println(y);
}
void incrZ() {
int z = 0;
z++;
IO.println(z);
}
}
|
public class Example {
public static void run() {
C a = new C();
C b = new C();
a.incrX();
a.incrX();
b.incrX();
a.incrY();
a.incrY();
b.incrY();
a.incrZ();
a.incrZ();
b.incrZ();
}
}
|
[5 pts] Consider the following method.
public static void sortBadly(double[] to_sort) {
for(int i = 0; i < to_sort.length; i++) {
int item = to_sort[i];
int dest = 0;
while(to_sort[dest] < item) {
dest++;
}
for(int j = i; j > dest; j--) {
to_sort[j] = to_sort[j - 1];
}
to_sort[dest] = item;
}
}
[15 pts] A matrix is symmetric if, for each i and j, ai,j = aj,i. The following is an example of a symmetric matrix.
| 0 | 23 | 45 |
| 23 | 10 | 36 |
| 46 | 36 | 20 |
public static boolean isSymmetric(int[][] mat) {
}
1 2 3 1 2 1 1 1 1
public static boolean isSymmetric(int[][] mat) {
for(int i = 0; i < mat.length; i++) {
for(int j = 0; j < mat.length; j++) {
if(mat[i][j] != mat[j][i]) return false;
}
}
return true;
}