![]() |
|
Sample midterm questions |
Color.green
and Color.blue
can be used as arguments to
setColor
to set the color of a square to green or blue.
public static void f() { int f1 = 1; int f2 = 1; System.out.println(f1); System.out.println(f2); for (int index = 3; index <= 10; index++) { int next = f1 + f2; System.out.println(next); f1 = f2; f2 = next; } }
accumulateArray
that takes an integer array
parameter A
and that returns an integer array B
where B[i]
is the sum of the entries from A[0]
to A[i]
.
For example, if A
contains, in order, the values 12, 8, 19, 25 then
the array B
that is returned contains the values 12, 20, 39, 64 in
that order.int[] A = {10, 20, 30, 40}; int[] B = {50, 60, 70, 80}; int[] C = new int[4]; for (int index = 0; index < B.length; index++) { C[index] = B[index]; } B = A;