Java Reference
In-Depth Information
c. What is the number of columns in the array sales ?
d. To sum the sales by CAR_TYPES , what kind of processing is required?
e. To sum the sales by COLOR_TYPES , what kind of processing is required?
30. Write Java statements that do the following:
a. Declare an array alpha of 10 rows and 20 columns of type int .
b. Initialize each element of the array alpha to 5 .
c. Store 1 in the first row and 2 in the remaining rows.
d. Store 5 in the first column, and the value in each remaining column is
twice the value of the previous column.
e. Print the array alpha one row per line.
f. Print the array alpha one column per line.
31. Consider the following declaration:
int [][] beta = new int [3][3];
What is stored in beta after each of the following statements executes?
a. for ( int i = 0; i < 3; i++)
for ( int j = 0; j < 3; j++)
beta[i][j] = 0;
b. for ( int i = 0; i < 3; i++)
for ( int j = 0; j < 3; j++)
beta[i][j] = i + j;
c. for ( int i = 0; i < 3; i++)
for ( int j = 0; j < 3; j++)
beta[i][j] = i * j;
d. for ( int i = 0; i < 3; i++)
for ( int j = 0; j < 3; j++)
beta[i][j] = 2 * (i + j) % 4;
32. In Java, as an actual parameter, can an array be passed by value?
33. Define a two-dimensional array named temp of 3 rows and 4 columns of
type int such that the first row is initialized to 6 , 8 , 12 , 9 ; the second
row is initialized to 17 , 5 , 10 , 6 ; and the third row is initialized to 14 ,
13 , 16 , 20 .
Suppose that array temp is as defined in Exercise 33. Write Java statements
to accomplish the following:
a. Output the contents of the first row and first column element of temp .
b. Output the contents of the first row and last column element of temp .
c. Output the contents of the last row and first column element of temp .
d. Output the contents of the last row and last column element of temp .
34.
Search WWH ::




Custom Search