13 consider the following 2 dimensional array select

Info icon This preview shows pages 4–7. Sign up to view the full content.

View Full Document Right Arrow Icon
13) Consider the following 2-dimensional array. Select the statement that gives the number of columns in the third row. int[][] counts ={{ 0, 0, 1 },{ 0, 1, 1, 2 },{ 0, 0, 1, 4, 5 },{0,2}} a- int cols = counts[2].size(); b- int cols = counts.length[2]; c- int cols = counts.length; d- int cols = counts[2].length; 14) Consider the following code snippet: String[] data = { "abc", "def", "ghi", "jkl" }; Which statement grows the data array to twice its size? a- data = Arrays.copyOf(data, 2 * data.length); b- data = Arrays.copyOf(data, 2); c- data = Arrays.copyOf(data, 2 * data); d- data = Arrays.copyOf(data, 2 * data.size()); 15) Which of the following is correct for simulating the toss of a pair of coins to get 0 (head) or 1 (tail) with different probabilities? a- (int) (Math.random() * 0 + 1) b- (int) (Math.random() * 2) + " " + (int) (Math.random() * 2) c- (int) (Math.random() * 2) d- (int) (Math.random() * 1 + 1) 16) When an array reading and storing input runs out of space a- the program could be recompiled with a bigger size for the array. b- the array could be "grown" using the growArray method. c- it automatically resizes to accommodate new elements. d- the array could be "grown" using the new command and the copyOf method. 17) What is the output of the code snippet given below? String s = "12345"; int i = 1; while (i < 5) { System.out.print(s.substring(i, i + 1)); i++;
Image of page 4

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
} a- No output b- 1234 c- 12345 d- 2345 18) What is the first and last value of i to be displayed by the following code snippet? int n = 20; for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { System.out.println("" + i); } } a- 0 and 20 b- 1 and 20 c- 0 and 19 d- 1 and 19 19) In a partially filled array, the number of slots in the array that are not currently used is a- the length of the array minus the number of elements currently in the array b- the number of elements currently in the array minus the length of the array c- the length of the array plus the number of elements currently in the array d- the number of elements currently in the array 20) What is the output of the following code snippet? int[] myarray = { 10, 20, 30, 40, 50 }; System.out.print(myarray[2]); System.out.print(myarray[3]); a- 1050 b- 2030 c- 3040 d- 4050 21) Which one of the following statements is a valid initialization of an array named somearray of ten elements? a- int[] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; b- int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; c- int[10] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; d- int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 22) Which of the following statements describes the scope of a local variable?
Image of page 5