Question: 1. The finally block of a try/catch structure will execute only if an exception occurs in the try block. True False 2. Evaluate the following
1. The finally block of a try/catch structure will execute only if an exception occurs in the try block.
True
False
2. Evaluate the following code to determine the output.
MyQueueq = new MyQueue (); q.add(30); q.add(58); q.add(94); q.remove();q.remove(); System.out.println(q.remove());
3. Evaluate the following code to determine what value will be at the top of the stack after the code completes.
MyStacks = new MyStack (); s.push(19); s.push(66); s.push(78);
4. Which of the following iterative methods is equivalent to this recursive method?
int foo(int n) { if (n <= 1) return n; return n + foo(n 1); } Group of answer choices
1) int foo(int n) { int x = n; while (n > 0) { n--; x += n; } return x; } 2) none of these
3) int foo(int n) { int x = 0; while (n > 0) { n--; x += n; } return x; } 4) int foo(int n) { int x = n; while (n > 0) { x += n; n--; } return x; }
5. Given that:
int[] list = {3,7,14,18,21,27,32,37,42,48,54,58,64,68,73}; and:
int targetValue = 4;
and given this Binary Search algorithm:
public static int BinarySearch(int[] list, int targetValue) { int mid, low, high; low = 0; high = list.length - 1; while (high >= low) { mid = (high + low) / 2; if (list[mid] < targetValue) { low = mid + 1; } else if (list[mid] > targetValue) { high = mid - 1; } else { return mid; } } return -1; // not found } Which value in list will be the third to be compared to the targetValue in a binary search for the target value?
6. Given the following sorting algorithm:
01 public static void selectionSort(int [ ] numbers) { 02 int i, j, temp; 03 int indexSmallest; 04 05 for (i = 0; i < numbers.length - 1; i++) { 06 07 // Find index of smallest remaining element 08 indexSmallest = i; 09 for (j = i + 1; j < numbers.length; j++) { 10 11 if (numbers[ j ] < numbers[ indexSmallest ]) { 12 indexSmallest = j; 13 } 14 } 15 16 // Swap numbers[ i ] and numbers[ indexSmallest ] 17 temp = numbers[ i ]; 18 numbers[ i ] = numbers[ indexSmallest ]; 19 numbers[ indexSmallest ] = temp; 20 } 21 } and applying it to the following list:
int[ ] numbers = {81, 39, 54, 4, 27, 69}; What value will be at index 3 in numbers after line# 19 executes 4 time(s)?
7. Given the following sorting algorithm:
01 public static void insertionSort(int [] numbers) { 02 int i, j, temp; 03 04 for (i = 1; i < numbers.length; ++i) { 05 j = i; 06 // Insert numbers1 into sorted part 07 // stopping once numbers1 in correct position 08 while (j > 0 && numbers[j] < numbers[j - 1]) { 09 10 // Swap numbers[j] and numbers[j - 1] 11 temp = numbers[j]; 12 numbers[j] = numbers[j - 1]; 13 numbers[j - 1] = temp; 14 --j; 15 } 16 } 17 } and applying it to the following list:
int[ ] numbers = {91, 38, 55, 10, 19, 78}; What value will be at index 1 in numbers after the while loop (on lines 08 - 15) finishes 2 time(s)?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
