Array Review
From Huben's Wiki
(Created page with "<code>1. int values[] = {1,2,3,4,5,6,7,8}; for(int i=0; i< X; i++) System.out.println(values[i]); Referring to the above, what value for X will print all members of array "...") |
|||
Line 1: | Line 1: | ||
− | < | + | <pre>1. |
int values[] = {1,2,3,4,5,6,7,8}; | int values[] = {1,2,3,4,5,6,7,8}; | ||
for(int i=0; i< X; i++) | for(int i=0; i< X; i++) | ||
System.out.println(values[i]); | System.out.println(values[i]); | ||
− | Referring to the above, what value for X will print all members of array "values"? | + | Referring to the above, what value for X will print |
+ | all members of array "values"? | ||
A) 1 B) 9 C) 7 D) 8 | A) 1 B) 9 C) 7 D) 8 | ||
− | E) None, since there is a syntax error in the array declaration | + | E) None, since there is a syntax error in the array |
− | 2. int[] number = new int[5]; After execution of this statement, which of the following are true? | + | declaration |
+ | |||
+ | 2. int[] number = new int[5]; After execution of this | ||
+ | statement, which of the following are true? | ||
(A) number[0] is 5 | (A) number[0] is 5 | ||
(B) number[i] is 0 | (B) number[i] is 0 | ||
Line 13: | Line 17: | ||
(D) number[2] is 0 | (D) number[2] is 0 | ||
(E) number.length() is 5 | (E) number.length() is 5 | ||
+ | |||
3. What does | 3. What does | ||
− | + | double table[]; | |
− | mean? | + | mean? |
A) table is a variable to refers to a real number | A) table is a variable to refers to a real number | ||
B) table is a variable that refers to two numbers | B) table is a variable that refers to two numbers | ||
Line 32: | Line 37: | ||
A) 0 B) 3 C) 10 D) unknown | A) 0 B) 3 C) 10 D) unknown | ||
− | 5. Declare and create a one-dimensional array called B with 5 elements of type integer. | + | 5. Declare and create a one-dimensional array called B |
− | 6. Declare and initialize a one-dimensional array called C with the following values: | + | with 5 elements of type integer. |
+ | |||
+ | 6. Declare and initialize a one-dimensional array called | ||
+ | C with the following values: | ||
10,20,60 and 40. | 10,20,60 and 40. | ||
+ | |||
7. What is the output of the following? | 7. What is the output of the following? | ||
int [] p = { 1, 2, 5, 8, 6}; | int [] p = { 1, 2, 5, 8, 6}; | ||
Line 42: | Line 51: | ||
} | } | ||
− | </ | + | </pre> |