JAVA Finals
JAVA Finals
JAVA Finals
JAVA Programming
TEST 1: True/False
Indicate whether the statement is true or false.
the statement
____ 5. The instance variable length contains the value of the last index in the
array.
____ 6. Arrays can be initialized when they are created.
____ 7. Loops can be used to step through the elements of a one-dimensional
array.
____ 8. Given the declaration
the statement
System.out.println(list);
outputs all 50 components of the array list, one component per line.
In this declaration, the array alpha has more components than the array
beta.
____ 20. The statement dataType[][][] arrayName; would declare a two-dimensional
array.
num[5] = 10;
num[55] = 100;
____ 22. What is the data type of the array above?
a. int c. list
b. char d. num
____ 23. How many components are in the array above?
a. 0 c. 99
b. 50 d. 100
____ 24. What is the value of num.length in the array above?
a. 0 c. 100
b. 99 d. 101
____ 25. Which of the following is the array subscripting operator in Java?
a. . c. new
b. {} d. []
____ 26. Which of the following statements creates alpha, an array of 5
components of the type int, and initializes each component to 10?
(i)
for (j = 0; j < 49; j++)
sales[j] = 10;
(ii)
for (j = 1; j <= 50; j++)
sales[j] = 10;
Which of the following correctly finds the sum of the elements of list?
(i)
sum = 0;
for (j = 0; j < 10; j++)
sum = sum + list[j];
(ii)
sum = list[0];
for (j = 1; j < 10; j++)
sum = sum + list[j];
a. 0 1 2 3 4 c. 0, 5, 10, 15, 20
b. 0 5 10 15 20 d. None of these
____ 31. What is the value of alpha[4] after the following code executes?
alpha[0] = 2;
for (j = 1; j < 5; j++)
alpha[j] = alpha[j – 1] + 3;
a. 5 c. 11
b. 8 d. 14
____ 32. What is the value of alpha[3] after the following code executes?
alpha[0] = 5;
for (j = 1; j < 5; j++)
{
if (j % 2 == 0)
alpha[j] = alpha[j – 1] + 2;
else
alpha[j] = alpha[j – 1] + 3;
}
a. 10 c. 15
b. 13 d. None of these
____ 33. What is stored in alpha after the following code executes?
if (j % 2 == 1)
alpha[j - 1] = alpha[j] + 2;
}
if (j % 2 == 1)
alpha[j - 1] = alpha[j] + j;
}
a. 2 4 6 8 10 c. 4 3 2 1 0
b. 10 8 6 4 2 d. Invalid code
hit[0] = 3;
hit[1] = 5;
hit[2] = 2;
hit[3] = 6;
hit[4] = 1;
System.out.println(hit[1 + 3]);
____ 36. What is the output of the code fragment above?
a. 1 c. 5
b. 3 d. 6
int[] array1 = {1, 3, 5, 7}
x[0] = 34;
x[1] = 88;
return count;
}
Which of the following statements best describe the behavior of this
method?
a. This method returns the number of values stored in list.
b. This method returns the sum of all the values of list.
c. This method returns the number of times item is stored in list.
d. None of these
____ 40. Given the following method heading
a. strange(alpha[0], alpha[1]);
b. strange(alpha, beta);
c. strange(alpha[0], beta);
d. strange(alpha, beta[0]);
____ 42. Consider the following declaration.
(i)
alpha = console.nextInt();
alpha = console.nextInt();
alpha = console.nextInt();
(ii)
alpha[0] = console.nextInt();
alpha[1] = console.nextInt();
alpha[2] = console.nextInt();
(i)
int[][] alpha = new int[10][5];
(ii)
int[][] alpha;
alpha = new int[10][];
for (int i = 0; i < 10; i++)
alpha[i] = new int[5];
a. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sales[5][j];
b. sum = 0;
for(j = 0; j < 7; j++)
sum = sum + sales[4][j];
c. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sales[5][j];
d. sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sales[4][j];