Java Reference
In-Depth Information
generations of the game. You may get extra credit if you implement a
graphical application that allows the user to add or remove cells by
clicking with the mouse.
ANSWERS TO SELF-CHECK QUESTIONS
1. 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, but not 100.
2.
a. 0
b. a run-time error: array index out of bounds
c. a compile-time error:
c
is not initialized
3.
new String[10];
new ArrayList<String>();
4.
names
contains the strings
"B"
and
"C"
at positions 0 and 1.
5.
double
is one of the eight primitive types.
Double
is a class type.
6.
data.set(0, data.get(0) + 1)
;
7.
for (double x : data) System.out.println(x)
;
8. The loop writes a value into
data[i]
. The Ȓfor eachȓ loop does not have
the index variable
i
.
9. It returns the first match that it finds.
10. Yes, but the first comparison would always fail.
11.
int[][] array = new int[4][4]
;
12.
int count = 0;
for (int i = 0; i < ROWS; i++)
for (int j = 0; j < COLUMNS; j++)
if (board[i][j].equals(" ")) count++;