finalexa - 1.00/1.001 Introduction to Computers and...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Exam / December 21, 2005 Name: Email Address: TA: Section: You have 180 minutes to complete this exam. For coding questions, you do not need to include comments, and you should assume that all necessary files have already been imported. Use of electronic devices (laptops, cell phones, calculators etc.) is not allowed. Good luck! Question Points Question 1 /16 Question 2 / 24 Question 3 / 36 Question 4 / 24 Total / 100 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Question 1: Short answer questions (16 pts): 1. A catch block can throw the exception it is handling a second time. TRUE FALSE 2. The following code will not compile because the stream is not closed. public void test() { try { FileWriter writer = new FileWriter( f ); } catch ( IOException e ) { System.out.println(“caught IOException”); } } TRUE FALSE 3. The runtime of insertion sort O(n 2 ) is always longer than the runtime of quicksort O(nlogn) on the same set of elements TRUE FALSE 4. Assume the following code fragment is part of a main() method that is part of a correctly structured class. int i = 0; double j=2; i = 2*j +1; System.out.println(i); Will the above code compile? __________ If yes, then what is the final value of i that will be printed on the screen? _________ 5. Assume the following code fragment is part of a main() method that is part of a correctly structured class. int[] intArray = new int[3]; for(int i=0;i<=3;i++) { intArray[i] = i+1; } The above code will run without any errors. TRUE FALSE 2
Background image of page 2
6. The following code will compile public class A { public int i; public static void main (String args[]) { i = 5; } } TRUE FALSE 7. What is the output from the following program? public class ConfusingStrings { public static String confused(String s) { return s += "This is confusing."; } public static void moreConfused (String s) { s += "This is even more confusing"; } public static void main(String[] args) { String s = "Simple String. "; System.out.println(s); s = confused(s); System.out.println(s); moreConfused(s); System.out.println(s); } } 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8. The short answer questions below refer to the following class definition: public class Name { private String first; private String last; public Name (String f, String l ) { first = f; last = l; } public boolean equals( Object b ) { if ( b instanceof Name ) { Name nb = (Name) b; return ( first.equals( nb.first ) && last.equals( nb.last )); } else return false; } } a. Name inherits a hashCode() method from Object . TRUE FALSE b. What will the following main method print? public static void main( String [] args ) { Name n1 = new Name( "Albert", "Einstein" ); Name n2 = new Name( "Albert", "Einstein" ); if ( n1.equals(n2)) System.out.println( "Yes "); else System.out.println( "No" ); if ( n1.hashCode() == n2.hashCode()) System.out.println( "Yes "); else System.out.println( "No" ); } 4
Background image of page 4
The next set of questions will be based on the following tree. 19
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

finalexa - 1.00/1.001 Introduction to Computers and...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online