CS38-Summer 2009-Final Exam_Solution

CS38-Summer 2009-Final Exam_Solution - Shouseman Page 1...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Shouseman Page 1 10/5/2011 JAVA- Final Exam-Solution Time allowed 2 hours Total = 20 points. Instruction: Complete all 40 multiple choice questions (0.5 POINT EACH), by marking the correct answer on Scranton (Form No. 882-E). Use a Pencil. 1. Which of the following for loops is valid, given the following declaration? String[] names = {“abc”, “def”, “ghi”, “jkl”}; A. for( int i = 0; i < names.length(); i++ ) System.out.println(names[i].length ()); B. for( int i = 0; i < names.length(); i++ ) System.out.println(names[i].length ); C. for( int i = 0; i < names.length; i++ ) System.out.println(names[i].length ()); D. for( int i = 0; i < names.length; i++ ) System.out.println(names[i].length); 2. When formulating a recursive solution, what should you consider? 3. The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>(); A.    It specifies that   String   objects may not be stored in the   ArrayList              object. B.    It specifies that everything stored in the    ArrayList    object will be converted to   String .
Image of page 1

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

View Full Document Right Arrow Icon
Shouseman Page 2 10/5/2011 C. It specifies that only String objects may be stored in the    ArrayList object . D. It specifies that only get method will return only String objects. . 4. Code that could generate a/an ___________________, such as an I O Exception, must be coded within a ____________. This is required. 5. You coded the following in the class Test.java ; import java.io.IOException; import java.io.File; import java.util.Scanner; public class Test { public static void main (String [] args) { try { Scanner file = new Scanner (new File( “data.txt”)); String stringRead = file.nextLine(); } catch (IOException ioe) { ioe.printStackTrace(); } System.out.prinln( “String read: “ + stringRead); // line above is line 19 } } At Compile Time, you get the following error: Test.java:19: cannot find symbol symbol : variable stringRead location: class Test System.out.prinln( “String read: “ + stringRead); ^ 1 error Explain what the problem is and how to fix it:
Image of page 2
Shouseman Page 3 10/5/2011 }
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern