PDA

View Full Version : Java


admiral9932
May 10, 2013, 11:58 AM
A programmer has written the following methods, which are supposed to insert an int into an OBT, and return the depth of an OBT respectively. Unfortunately there are some errors. Assume appropriate definitions for the instance variables empty, value, left and right, and the method setValue(), as shown in COMP16212.

public void insert(int insertValue)
{
}
public int getDepth()
{
else
{
} }
if (empty) setValue(insertValue);

else if (insertValue < value) left.insert(insertValue);

else right.insert(insertValue);

if (empty) return 0;
int leftDepth = left.getDepth(); int rightDepth = right.getDepth(); if (leftDepth > rightDepth)
return leftDepth + value; else
return rightDepth + value;

He or she creates an OBT by starting with an empty one, and inserting the numbers 15, 12, 8, 13, 20, 16, 25 in that order. What value would be returned by the getDepth() method, if it was invoked on the root node of the resulting tree?

admiral9932
May 10, 2013, 12:02 PM
Given the following initialized Java declaration:

PrintWriter out = new PrintWriter(new FileWriter("films.txt"));
which one of the following statements is true?

A. Whenever the statement
out.println("Welcome to films.txt");
is executed it will always write the string "Welcome to films.txt" to standard
output.

B. An exception is thrown when the declaration is executed in a context where the
file named films.txt has write-only permission.

C. IftheStringvariablesisnullwhenthestatement
out.print(s);
is executed, a NullPointerException object will be thrown.

D. ARuntimeExceptionexceptionwillalwaysbethrownwhenth estatement out.print("What is infinity? " + 1.0/0.0);
is executed.

E. The statement
out.close();
will compile without error because the PrintWriter class has a close() method,
as files are not closed safely on normal termination.

JTLUOM
May 14, 2013, 08:52 PM
Hi there admiral9932. I just wanted to ask you how did you get this question? The thing is you cannot have this because it is not available and allowed in our uni website . As a corollary of this, we are going to find your address and who you are by your IP address. We will take these all into account and if you are CS student in Manchester university. You will be out of university. Good luck in your exams
Mr John Latham