Exam 7: Arrays and Array Lists

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

Suppose you wish to write a method that returns the sum of the elements in the partially filled array myArray. Which is a reasonable method header?

Free
(Multiple Choice)
4.9/5
(33)
Correct Answer:
Verified

C

What is the output of the given code snippet? Int[] mynum = new int[5]; For (int i = 1; i < 5; i++) { Mynum[i] = i + 1; System.out.print(mynum[i]); }

Free
(Multiple Choice)
4.9/5
(45)
Correct Answer:
Verified

A

The following statement gets an element from position 4 in an array: x = a[4]; What is the equivalent operation using an array list?

Free
(Multiple Choice)
4.8/5
(42)
Correct Answer:
Verified

A

Identify the correct statement for defining an integer array named numarray of ten elements.

(Multiple Choice)
4.9/5
(41)

Consider the following code snippet: public static void check(ArrayList<Integer> chknum1) { Int cnt = 0; For(int i = 0; i < chknum1.size(); i++) { If(chknum1.get(i) == 0) { Cnt++; } } System.out.println("The total 0 values in the list are: " + cnt); } Which one of the following is true about the check method in the given code snippet?

(Multiple Choice)
4.9/5
(28)

What is the output of the following code snippet? public static int check(ArrayList<Integer> listData) { Int sum = 0; For (int i = 0; i < listData.size(); i++) { Sum = sum + listData.get(i); } Return sum; } Public static void main(String[] args) { ArrayList<Integer> vdata = new ArrayList<Integer>(); Int rsum; For (int cnt = 0; cnt < 3; cnt++) { Vdata.add(cnt + 1); } Rsum = check(vdata); System.out.println(rsum); }

(Multiple Choice)
4.7/5
(42)

The enhanced for loop

(Multiple Choice)
4.8/5
(33)

Consider the telephone book as a physical object that can help understand algorithms. What kind of algorithm might be visualized using it?

(Multiple Choice)
4.9/5
(36)

Which one of the following is a valid signature of a method with an integer two-dimensional array parameter of size 10 x 10?

(Multiple Choice)
4.8/5
(35)

Which one of the following statements is correct for the given code snippet? Int[] number = new int[3]; // Line 1 Number[3] = 5; // Line 2

(Multiple Choice)
4.9/5
(45)

The integer array numbers will be filled with the values from the Scanner in. If there are more input values than there are spaces in the array, only enough values to fill the array should be read. The integer variable currentSize should be set to the number of values read. Partial code to do this is given below: Int[] numbers; // Assume it is created with at least 1 space Scanner in = new Scanner (System.in); Int currentSize = 0; While (/* Put condition here */) { Int value = in.nextInt(); Numbers[currentSize] = value; CurrentSize++; } What condition will complete this code?

(Multiple Choice)
4.8/5
(45)

Which one of the following statements is true about passing arrays to a method?

(Multiple Choice)
5.0/5
(42)

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

(Multiple Choice)
4.9/5
(30)

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 val: values) { If (/* Put condition here */) Max = val; }

(Multiple Choice)
4.8/5
(32)

What is the result of the following definition of an array list? ArrayList<Double> points;

(Multiple Choice)
4.8/5
(30)

Suppose you wish to use an array to solve a new problem. What is the first step to take in finding a solution?

(Multiple Choice)
4.8/5
(36)

What is the output of the following statements? ArrayList<String> cityList = new ArrayList<String>(); CityList.add("London"); CityList.add("New York"); CityList.add("Paris"); CityList.add("Toronto"); CityList.add("Hong Kong"); CityList.add("Singapore"); System.out.print(cityList.size()); System.out.print(" " + cityList.contains("Toronto")); System.out.print(" " + cityList.indexOf("New York")); System.out.println(" " + cityList.isEmpty());

(Multiple Choice)
4.8/5
(47)

Consider the following code snippet. Which statement should be used to fill in the empty line so that the output will be [32, 54, 67.5, 29, 35]? public static void main(String[] args) { Double data[] = {32, 54, 67.5, 29, 35}; ______________ System.out.println(str); }

(Multiple Choice)
4.9/5
(34)

What is the value of the cnt variable after the execution of the code snippet below? ArrayList<Integer> somenum = new ArrayList<Integer>(); Somenum.add(1); Somenum.add(2); Somenum.add(1); Int cnt = 0; For (int index = 0; index < somenum.size(); index++) { If (somenum.get(index) % 2 == 0) { Cnt++; } }

(Multiple Choice)
4.7/5
(33)

Consider the following code snippet: ArrayList<Double> somedata = new ArrayList<Double>(); Somedata.add(10.5); What is the size of the array list somedata after the given code snippet is executed?

(Multiple Choice)
4.8/5
(37)
Showing 1 - 20 of 118
close modal

Filters

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