| CIT591 Midterm Exam Fall, 2003 |
Name_________________________________________ |
Please keep all your answers short and to the point. Do not provide extra information that was not asked for.
int p = 1;
for (int i = 0; i < 5; i++) {
p += i;
System.out.print(p);
}
public class Product {
int x = 5, y = 8, p = 0;
while (x > 0) {
x--;
p = p + y;
}
System.out.print(x + " times " + y + " equals " + p);
}
boolean ok(int[] array, int index) { boolean legal; if (index < 0) { legal = false; } else if (index >= array.length) { legal = false; } else { legal = true; } return legal; }
public class ArrayTest {
public static void main(String[] args) {
int[] test = new int[2];
test[0] = test[1] = 5;
System.out.println(test[0] + "," + test[1]);
fiddle(test, test[1]);
System.out.println(test[0] + "," + test[1]);
}
static void fiddle(int[] test, int element) {
test[0] = 10;
test[1] = 11;
element = 12;
System.out.println(test[0] + "," + test[1] + "," + element);
test = new int[2];
test[0] = 20;
test[1] = 21;
System.out.println(test[0] + "," + test[1]);
}
}
java.lang.NullPointerException
at Test.run(Test.java:22)
at Test.main(Test.java:6)
at __SHELL1.run(__SHELL1.java:6)
at bluej.runtime.ExecServer.suspendExecution(ExecServer.java:187)
at bluej.runtime.ExecServer.main(ExecServer.java:69)
Tell where in the program the error occurred, and what you expect
to find when you look there.