Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These are the questions i couldnt get over the semester. Thanks for your help Question 1 What is stored in alpha after the following code

These are the questions i couldnt get over the semester. Thanks for your help

Question 1 What is stored in alpha after the following code executes? int[] alpha = new

int[5];

 for (int j = 0; j < 5; j++) { 
 alpha[j] = 2 * j; if (j % 2 == 1) 

alpha[j - 1] = alpha[j] + j;

} A. alpha={0,2,4,6,8}

B. alpha={3,2,9,6,8}

C. alpha={0,3,4,7,8}

D. alpha={0,2,9,6,8}

Question 2

char[][] table = new char[10][5]; What is the value of table.length? A. 0 B. 5

C. 10 D. 15

Question 3.

Suppose you have the following declaration.

double[] salesData = new double[500]; Which of the following range is valid for the index of the array salesData.

(i) 0 through 500

(ii) (ii) 0 through 499

A. Only (i) B. Only (ii) C. Both are invalid D. None of these

Question 4

char[][] table = new char[10][5]; 

How many columns are in the array seen in the accompanying figure?

A. 0 B. 5 C. 10 D. 15

Question 5

An abstract method ____.

A. is any method in the abstract class

B. cannot be inherited has no body

C. is found in a subclass and overrides methods in a superclass using the D. reserved word abstract

Question 6 What type of inheritance does Java support?

A. single inheritance B. double inheritance C. multiple inheritance D. Java does not support inheritance.

Question 7 Consider the following class definitions.

public class BClass { 
 private int x; private double y; public void print() { } 
} public class DClass extends BClass { 
 private int a; private int b; public void print() { } 

}

Suppose that you have the following statement.

DClass dObject = new DClass(); How many instance variables does dObject have?

A. zero B. two C. three D. four

Question 8

int number; boolean done = false; 

do { try

{ System.out.print("Enter an integer: "); number = console.nextInt();

 System.out.println(); done = true; System.out.println("number = " + number); 
 } catch (InputMismatchException imeRef) { 

}}

while (!done); str = console.next(); System.out.println("Exception " 
 + imeRef.toString() + " " + str); 

Which exception-handling technique is the code in the accompanying figure using?

A. Terminate the program. B. Fix the error and continue.

C. Log the error and continue.

D. None of the above.

Question 9

import java.util.*; public class ExceptionExample1 { 
 static Scanner console = new Scanner(System.in); public static void main(String[] args) { 
 int dividend, divisor, quotient; 
try { quotient); } 
System.out.print("Enter dividend: "); dividend = console.nextInt(); System.out.println(); System.out.print("Enter divisor: "); divisor = console.nextInt(); System.out.println(); 

quotient = dividend / divisor; System.out.println("quotient = " +

 catch (ArithmeticException aeRef) { 
 System.out.println("Exception" + aeRef.toString()); 

}} }

} catch (InputMismatchException imeRef) { 
 System.out.println("Exception " + imeRef.toString()); 
} catch( IOException ioeRef) { 
 System.out.println("Exception " + ioeRef.toString()); 

Which method throws the second exception in the code in the accompanying figure?

A. nextInt B. toString C. println D. nextLine

Question 10

How many finally blocks can there be in a try/catch structure?

There must be one finally block.

There can be one finally block following each catch block.

There can be zero or one finally blocks following the last catch block.

There is no limit to the number of finally blocks following the last catch

block.

Question 11

Which of the following is NOT a typical action of the catch block?

A. Completely handling the exception B. Partially processing of the exception C. Rethrowing the same exception for the calling environment D. Throwing the exception

Question12

public static int func1(int m, int n) { 
 if (m == n || n == 1) return 1; 

else return func1(m - 1, n - 1) + n * func1(m - 1,

n); }

What precondition must exist in order to prevent the code in the accompanying figure from infinite recursion?

A.m>=0 andn>=0 B. m >= 0 and n >= 1 C.m>=1 andn>=0 D. m >= 1 and n >= 1

Question 13

What is the first step in the Tower of Hanoi recursive algorithm?

Move the top n disks from needle 1 to needle 2, using needle 3 as the intermediate needle.

Move disk number n from needle 1 to needle 3.

Move the top n - 1 disks from needle 2 to needle 3, using needle 1 as the

intermediate needle.

Move the top n - 1 disks from needle 1 to needle 2, using needle 3 as the

intermediate needle.

Question 14

list: 16, 30, 24, 7, 25, 62, 45, 5, 65, 50

Why cant a binary search be used on the list as it appears in the accompanying figure?

A. Because the list is too big

B. Because the list is not sorted

C. Because it is a list of integers D. A binary search can be used on the list

Question 15

list: 16, 30, 24, 7, 25, 62, 45, 5, 65, 50

If the list in the accompanying figure was sorted, what would be the middle element?

A. 7

B. 16

C. 24

D. 45

Question 16

list 4, 18, 29, 35, 44, 59, 65, 98

If the list in the accompanying figure was to be searched for the number 44 using a binary search, how many key comparisons would have to be made?

A. 1 B. 3 C. 5 D. 7

Question 17

Consider the following list.

 list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47}; 

Suppose that sequential search as discussed in the book is used to determine whether 95 is in list. Exactly how many key comparisons are executed by the sequential search algorithm?

A. 1 B. 8 C. 9 D. 10

Question 18

list: 16, 30, 24, 7, 25, 62, 45, 5, 65, 50

If the list in the accompanying figure was sorted using selection sort, which two elements would be swapped first?

5 and 16

65 and 16

5 and 45

7 and 30

Question 19

list: 4, 18, 29, 35, 44, 65, 98

If a binary search was used on the list in the accompanying figure, which element would the search element be compared to first?

A. 4 B. 35 C. 44 D. 98

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

=+Which associations exist?

Answered: 1 week ago