Exam 7: Arrays and Array Lists

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which one of the following statements is the correct definition for a two-dimensional array of 20 rows and 2 columns of the type integer?

(Multiple Choice)
4.8/5
(42)

Which one of the following is the correct definition for initializing data in a two-dimensional array of three rows and two columns?

(Multiple Choice)
4.8/5
(42)

Is there any thing wrong with the following code snippet? String[] data = { "abc", "def", "ghi", "jkl" }; String searchedValue = "ghi"; Int pos = 0; Boolean found = false; While (pos < data.length) { If (data[pos].equals(searchedValue)) { Found = true; } Else { Found = false; } Pos++; } If (found) { System.out.println("Found at position: " + pos); } Else { System.out.println("Not found"); }

(Multiple Choice)
4.8/5
(40)

When an integer literal is added to an array list declared as ArrayList<Integer>, Java performs:

(Multiple Choice)
4.8/5
(38)

What is the valid range of index values for an array of size 10?

(Multiple Choice)
4.7/5
(28)

Which one of the following statements about declaring an array list as a method parameter is true?

(Multiple Choice)
4.7/5
(40)

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]);

(Multiple Choice)
4.9/5
(42)

Consider the following code snippet: String[] data = { "abc", "def", "ghi", "jkl" }; Using Java 6 or later, which statement grows the data array to twice its size?

(Multiple Choice)
4.9/5
(41)

What will be printed by the statements below? Int[] values = { 10, 24, 3, 64}; Int position = 0; For (int i = 1; i < values.length; i++) If (values[i] > values[position]) Position = i; System.out.print (position);

(Multiple Choice)
4.8/5
(34)

Consider the following code snippet: Int cnt = 0; Int[][] numarray = new int[2][3]; For (int i = 0; i < 3; i++) { For (int j = 0; j < 2; j++) { Numarray[j][i] = cnt; Cnt++; } } What is the value of numarray[1][2] after the code snippet is executed?

(Multiple Choice)
4.9/5
(36)

What is the result of the following code? for (double element : values) { Element = 0; }

(Multiple Choice)
4.8/5
(31)

Which statements about the enhanced for loop are true for arrays of primitve data? I. It is suitable for all array algorithms II. It does not allow the contents of the array to be modified III. It does not require the use of an index variable

(Multiple Choice)
4.8/5
(35)

What will be printed by the statements below? Int[] values = { 10, 20, 30, 7}; Int[] numbers = values; Numbers[2] = 24; Values[3] = numbers[0] + 6; System.out.println (numbers[2] + " " + numbers[3] + " " + values[2] + " " + values[3]);

(Multiple Choice)
4.9/5
(48)

What should you check for when calculating the smallest value in an array list?

(Multiple Choice)
4.8/5
(36)

The method findLargest should return the largest of any number of double values. For example, the call findLargest (3.4, -2.6, 2.9) should return 3.4 and the call findLargest (9.2, 17.6, 3.4, -2.6, 2.9) should return 17.6. Partial code to do this is given below: double findLargest (double... values) { Double max = values[0]; // New code goes here Return max; } What code will complete this method?

(Multiple Choice)
4.8/5
(39)

Consider the following code snippet: Int val = arr[0][2]; Which value of arr is stored in the val variable?

(Multiple Choice)
4.9/5
(40)

Which one of the following statements is a valid initialization of an array named somearray of ten elements?

(Multiple Choice)
5.0/5
(38)

When an array myArray is only partially filled, how can the programmer keep track of the current number of elements?

(Multiple Choice)
4.8/5
(32)
Showing 101 - 118 of 118
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)