Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What is the output of the following statements? ArrayList names = new ArrayLi

ID: 3693035 • Letter: 1

Question

1.

What is the output of the following statements? ArrayList names = new ArrayList(); names.add("Bob"); names.add(0, "Ann"); names.remove(1); names.add("Cal"); names.set(2, "Tony"); for (String s : names) { System.out.print(s + ", "); }

Select one:

a. Cal, Bob, Ann

b. Ann, Bob

c. Ann, Cal, Tony

d. Array list bound error

2.

Consider the following 2-dimensional array. Select the statement that gives the number of columns in the third row.

Select one:

a. int cols = counts[2].size();

b. int cols = counts.length[2];

c. int cols = counts.length;

d. int cols = counts[2].length;

3.

Consider the following code snippet:

Identify the appropriate statement to display the value 24 from the given array?

Select one:

a. System.out.println(arr[1][2]);

b. System.out.println(arr[2][2]);

c. System.out.println(arr[1][1]);

d. System.out.println(arr[2][1])

4.

Consider the following line of code for calling a method named func1:

Which one of the following method headers is valid for func1, where listData is an integer array list and varData is an integer variable?

Select one:

a. public static void func1(int[] listData, int varData)

b. public static void func1(ArrayList<Integer> listData, varData)

c. public static void func1(ArrayList<Integer> ldata, int vdata)

d. public static void func1(int vdata, ArrayList<Integer> ldata)

5.

Which one of the following code snippets accepts the integer input in an array list named num1 and stores the even integers ofnum1 in another array list named evennum?

Select one:

a.

b.

c.

d.

6.

Which one of the following statements is correct for displaying the value in the second row and the third column of a two-dimensional, size 3 by 4 array?

Select one:

a. System.out.println(arr[1][2]);

b. System.out.println(arr[2][3]);

c. System.out.println(arr[2][1]);

d. System.out.println(arr[3][2]);

7.

Select the statement that reveals the logic error in the following method.

Select one:

a. double m = minimum(new double[] { 1.2, -3.5, 6.6, 2.4 });

b. double m = minimum(new double[] { 1.2, 23.5, 16.6, -23.4 });

c. double m = minimum(new double[] { -10.2, 3.5, 62.6, 21.4 });

d. double m = minimum(new double[] { 12.2, 31.5, 6.6, 2.4 });

8.

What is the result of executing this code snippet?

Select one:

a. The code snippet does not give any output.

b. The code snippet displays all the marks stored in the array without any redundancy.

c. The code snippet causes a bounds error.

d. The code snippet executes an infinite loop.

What is the result of executing this code snippet?

Select one:

a. The code snippet does not give any output.

b. The code snippet displays all the marks stored in the array without any redundancy.

c. The code snippet causes a bounds error.

d. The code snippet executes an infinite loop.

9.

Is there any thing wrong with the following code snippet?

Select one:

a. There is nothing wrong.

b. There is compile-time error.

c. There is a bounds error.

d. There is a logic error.

10.

Which statements are true regarding the differences between arrays and array lists?

I. Arrays are better if the size of a collection will not change

II. Array lists are more efficient than arrays

III. Array lists are easier to use than arrays

Select one:

a. I, II

b. I, III

c. II, III

d. I, II, III

Explanation / Answer


Please follow the answers sequentially :

Provided the correct options with the brief expalanation.

1) OPTION D

Result - Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

2) OPTION D

Result - 5, The length function requires an array to get the count of elements.

3) OPTION C

Result - 24, Array indexing starts at 0.

4) OPTION C

Result - A function can be called using the local variables and the arraylist with the arraylist collection.

5) OPTION A

Result - 1 2 3 4 5 6 7 8 9 10
Output - When printed it is displayed as 2, 4, 8, 10
As the arraylists can be added up with the add method the option suits correctly.

6) OPTION A

Result - 34(user defined value), As the array indexing starts from 0 to get the value at the second row third column array[1][2] returns it.

7) OPTION D

Result - 0.0, As all the given values are greater than 0 that is pre defined.

8) OPTION C

Result - 90 45 67 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3, As the code written in the for loop checks for the value in the 3rd index even which is not present it prints the value already stored with an exception.

9) OPTION D

Result - Not Found
As the logic could not traverse through the list the same not found is being displayed.

10) OPTION D
Result - As all the statements are true regarding the arraylists.

Hope this is useful.