Techne 07
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?
1
whats the value of the count variable after the code exicutes? ArrayList<Integer> somenum = new ArrayList<Integer>(); somenum.add(1); somenum.add(2); somenum.add(1); int count = 0; for (int index = 0; index < somenum.size(); index++) { if (somenum.get(index) % 2 == 0) { count++; } }
1
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]); }
2345
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);
3
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]);
3040
Assume the following variable has been declared and given a value as shown: int[] numbers = {9, 17, -4, 21 }; Which is the value of numbers.length?
4
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); }
6
Which one of the following statements is true about using arrays with methods?
Arrays can be method arguments, and return values, just like any other values.
When the order of the elements is unimportant, what is the most efficient way to remove an element from an array?
Replace the element to be deleted with the last element in the array.
Consider the following code snippet, where the array lists contain elements that are stored in ascending order: ArrayList<Integer> list1 = new ArrayList<Integer>(); ArrayList<Integer> list2 = new ArrayList<Integer>(); . . . int count = 0; for (int i = 0; i < list1.size() && i < list2.size(); i++) { if (list1.get(i) == list2.get(i)) { count++; } } Which one of the following descriptions is correct for the given code snippet?
The code snippet compares the values of two array lists and stores the count of total matches found.
String[] data = { "abc", "def", "ghi", "jkl" }; String [] data2; In Java 6 and later, which statement copies the data array to the data2 array?
data2 = Arrays.copyOf(data, data.length);
Select the statement that reveals the logic error in the following method. public static double minimum(double[] data) { double smallest = 0.0; for (int i = 0; i < data.length; i++) { if (data[i] < smallest) { smallest = data[i]; } } return smallest; }
double m = minimum(new double[] { 12.2, 31.5, 6.6, 2.4 });
Complete the following code snippet with the correct enhanced for loop so it iterates over the array without using an index variable. String[] arr = { "abc", "def", "ghi", "jkl" }; ___________________ { System.out.print(str); }
for (String str : arr)
If currLength is an integer variable that gives the number of elements currently in the array myArray, which code snippet prints out the elements in the partially filled array of integers?
for (int i = 0; i < currLength; i++) { System.out.print(myArray[i]); }
Consider the telephone book as a physical object that can help understand algorithms. What kind of algorithm might be visualized using it?
searching
Regression testing is:
the process of testing each version of a program against a test suite.
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; }
val > max