Starting from:

$20

Final_exam 1. A search algorithm Solution

Quick Links

QUESTION 1

1. A search algorithm



Arranges elements in descending order


Arranges elements in ascending order


Is a way to locate a specific item in a larger collection of data


Is rarely used with arrays
6 points

QUESTION 2

1. Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement



str.toUpperCase();


str[0].toUpperCase();


str.uppercase();


str[0].upperCase();
6 points

QUESTION 3

1. If lower is the first subscript in a contiguous portion of an array, and upper is the last subscript, then the array item in the middle of that array portion is at subscript



(lower — upper)/2


(lower + upper)/2


(upper — lower)/2


lower + upper/2
6 points

QUESTION 4

1. If a class contains an abstract method,



The method must be overridden in subclasses


You cannot create an instance of the class


The method will have only a header, but not a body, and end with a semicolon


All of the above
6 points

QUESTION 5

1. In an interface all methods have



private access


protected access


public access


packaged access
6 points

QUESTION 6

1. In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file:

double totalIncome = 0.0;
while (inputFile.hasNext())
{
try
{
totalIncome += inputFile.nextDouble();
}
catch(InputMismatchException e)
{
System.out.println("Non-numeric data encountered " +
"in the file.");
inputFile.nextLine();
}
finally
{
totalIncome = 35.5;
}
}

What will be the value of totalIncome after the following values are read from the file?
2.5
8.5
3.0
5.5
abc
1.0



35.5


75.0


19.5


0.0
6 points

QUESTION 7

1. The binary search algorithm



is less efficient than the sequential search algorithm


will have a maximum number of comparisons equal to the number of elements in the array


will cut the portion of the array being searched in half each time the loop fails to locate the search value


will have an average of N/2 comparisons, where N is the number of elements in the array
6 points

QUESTION 8

1. The method findMax shown below is supposed to return the position of the largest
value in the portion of an array between 0 and last, inclusive:

int findMax(int array[ ], int last)
{
int maxPos = 0;
for (int k = 1; k <= last; k++)
{
// Code is Missing

}
return maxPos;
}
The missing code is



if (array[k] array[maxPos]) maxPos = k;


if (array[k] array[maxPos]) return maxPos;


if (array[k] maxPos) return maxPos;


if (array[k] array[maxPos]) k = maxPos;
6 points

QUESTION 9

1. The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

True

False

6 points

QUESTION 10

1. The catch clause



contains code to gracefully handle the exception type listed in the parameter list


starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable


follows the try clause


All of the above
6 points

QUESTION 11

1. This ArrayList class method is used to insert an item into an ArrayList.



store


insert


add


putItem
6 points

QUESTION 12

1. To convert the double variable, d = 543.98, to a string, use the following statement.



String str = double(d);


String str = Double.toString(d);


String str = double.toString(d);


String str = d.Double.toString(str);
6 points

QUESTION 13

1. Use the following import statement when using the Character wrapper class



import java.lang.Char


import java.String


import java.Char


No import statement is needed
6 points

QUESTION 14

1. What is the value of str after the following code has been executed?

String str;
String sourceStr = "Hey diddle, diddle, the cat and the fiddle";
str = sourceStr.substring(12,17);





diddle


, didd


Iddle


diddl
6 points

QUESTION 15

1. What is wrong with the following code?

public class ClassB extends ClassA
{
public ClassB()
{
int init = 10;
super(40);
}
}



Nothing is wrong with the code


The call to the method super must be the first statement in the constructor


No values may be passed to super


The method super is not defined
6 points

QUESTION 16

1. What will be printed when the following code is executed?

double x = 45678.259;
DecimalFormat formatter =
new DecimalFormat("#,##0.0");
System.out.println(formatter.format(x));





45,678.26


45,678.3


45678.259


45,678.259
6 points

QUESTION 17

1. API 4.0 best describes which framework?



Honeycomb


KitKat


Jelly Bean


Ice Cream Sandwich
6 points

QUESTION 18

1. JDBC connectivity requires drivers for any database.

True

False

6 points

QUESTION 19

1. The statement below puts the app to sleep for how long?

Thread.sleep(1000);





1 second


1000 seconds


1 miliisecond


1 minute
6 points

QUESTION 20

1. Which best defines a class that takes care of creating an Android window for you in which you can place your UI?



An event


An activity


A view component


The content provider
6 points

QUESTION 21

1. Which best describes a JDBC driver?



An interface for a Java app to interact with a database.


A class for a Java app to interact with a database.


A statement that allows for a connection to a database.


A pool of classes to allow for a connection to a database.
6 points

QUESTION 22

1. Which is not a class or interface of JDBC DriverManager?



Statement


Connection


DriverManagaer


JDBC
6 points

QUESTION 23

1. Which is a proper URL connection string to connect a mysql database called sales located on your local machine in the tempdb directory in the root of the c: drive?



jdbc:mysql//localhost/c:/tempdb/sales


jdbc//mysql//localhost/c:/tempdb/sales


jdbc:mysql://localhost/c:/tempdb/sales


jdbc:mysql:localhost/c:/tempdb/sales
6 points

QUESTION 24

1. Suppose that x and y are int variables and x = 7 and y = 8. After the statement: x = x * y - 2; executes, the value of x is ____.



42


54


56


58
6 points

QUESTION 25

1. Consider a class that uses the following variables to implement an array-based stack:

The boolean method to check for an empty stack can be written as:



return top;



6 points

Bottom of Form

More products