Exam 7: Arrays and Array Lists

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

Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); Int data; Scanner in = new Scanner(System.in); For (int i = 0; i < 5; i++) { Data = in.nextInt(); Num1.add(data); If (data == 0 && num1.size() > 3) { Num1.remove(num1.size() - 1); } } System.out.println("size is : " + num1.size()); What is the output of the given code snippet if the user enters 1,2,0,0,1 as the input?

(Multiple Choice)
4.8/5
(33)

Which code snippet calculates the sum of all the even elements in an array values?

(Multiple Choice)
4.9/5
(39)

Which statement is true about the code snippet below? ArrayList<String> names = new ArrayList<String>(); Names.add("John"); Names.add("Jerry"); ArrayList<String> friends = new ArrayList<String>(names); Names.add("Harry");

(Multiple Choice)
4.8/5
(33)

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

(Multiple Choice)
4.8/5
(36)

Which one of the following statements is correct about the given code snippet? Int[] somearray = new int[6]; For (int i = 1; i < 6; i++) { Somearray[i] = i + 1; }

(Multiple Choice)
4.8/5
(41)

What will be printed by the statements below? Int[] values = { 10, 20, 30, 40}; For (int i = 1; i < values.length; i++) Values[i] = values[i - 1]; For (int i = 0; i < values.length; i++) System.out.print (values[i] + " ");

(Multiple Choice)
4.9/5
(40)

Consider the following code snippet in Java 6 or later: String[] data = { "abc", "def", "ghi", "jkl" }; String[] data2 = Arrays.copyOf(data, data.length - 1); What does the last element of data2 contain?

(Multiple Choice)
4.8/5
(40)

Assume the following variable has been declared and given a value as shown: Int[][] data = { {9, 17, -4, 21 }, {15, 24, 0, 9}, {6, 2, -56, 8}, }; Which is the value of data.length?

(Multiple Choice)
4.9/5
(36)

What is the output of the following code snippet? public static void main(String[] args) { String[] arr = { "aaa", "bbb", "ccc" }; Mystery(arr); System.out.println(arr[0] + " " + arr.length); } Public static void mystery(String[] arr) { Arr = new String[5]; Arr[0] = "ddd"; }

(Multiple Choice)
4.8/5
(33)

What is the output of the code snippet below? Int[][] numarray = { { 8, 7, 6 }, { 0, 0, 0 } }; System.out.print(numarray[0][0]); System.out.print(numarray[1][0]);

(Multiple Choice)
4.9/5
(35)

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 } };

(Multiple Choice)
4.9/5
(30)

Which statements are true about the buffer overrun attack launched over the Internet in 1988? I. The buffer overrun exploited a program that was written in C running on the Unix operating system II. The Java programming language generates a run-time exception when buffer overrun occurs III. In recent years computer attacks have lessened

(Multiple Choice)
4.9/5
(41)

Assume the array of integers values has been created. Which condition must be used in the indicated area so the loop below will assign max the largest value in values? Int max = values[0]; For (int current = 1; current < values.length; current++) { If (/* Put condition here */) Max = values[current]; }

(Multiple Choice)
4.7/5
(43)

Your program needs to store an integer sequence of unknown length. Which of the following is most suitable to use?

(Multiple Choice)
4.7/5
(34)

Consider the following code snippet: String[] data = { "abc", "def", "ghi", "jkl" }; String [] data2; In Java 6 and later, which statement copies the data array to the data2 array?

(Multiple Choice)
4.8/5
(35)

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?

(Multiple Choice)
4.9/5
(38)

Which code snippet calculates the sum of all the elements in even positions in an array?

(Multiple Choice)
4.8/5
(36)

What is the value of the count variable after the execution of the given code snippet? ArrayList<Integer> num = new ArrayList<Integer>(); Num)add(1); Num)add(2); Num)add(1); Int count = 0; For (int i = 0; i < num.size(); i++) { If (num.get(i) % 2 == 0) { Count++; } }

(Multiple Choice)
4.9/5
(36)

Which statements about array algorithms are true? I. The array algorithms are building blocks for many programs that process arrays II. Java contains ready-made array algorithms for every problem situation III. It is inefficient to make multiple passes through an array if you can do everything in one pass

(Multiple Choice)
4.9/5
(41)

Consider the following line of code: Int[] somearray = new int[30]; Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?

(Multiple Choice)
4.9/5
(35)
Showing 61 - 80 of 118
close modal

Filters

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