Computer Science 61B - Fall 2001 - Hilfinger - Midterm 1

Computer Science 61B - Fall 2001 - Hilfinger - Midterm 1 -...

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

View Full Document Right Arrow Icon
CS 61B, Midterm #1, Fall 2001 CS 61B Midterm #1 Fall 2001 Professor Paul Hilfinger Throughout this test, assume that the following definitions are available. class IntList { public int head; public IntList tail; /** The IntList whose head is HEAD and whose tail is TAIL. */ public IntList (int head, IntList tail) { . .. } /** Return the reverse of L (non-destructively). */ static IntList reverse (IntList L) { . .. } } Problem #1: [5 points] a. Your Java program keeps throwing a ClassCastException on a line of your program that reads v = (String) values.pop (); where values is a java.util.Stack . As a first step in figuring out what's going on, you want to find out what value is about to be popped at this point. Tell what commands you would give gjdb to find out. b. I add a new source file, mymath/Vector.java , to my mcalc project, but don't change my Makefile . Usually, comilation (with gmake ) continues to work, but occasionally, something goes wrong. What, and under what conditions? c. Another student shows you this fragment of program text: { List L = createList(); fillValues(L); if (L.contains (x)) {. .. TheProgram stops with a NullPointerException at the if statement, so the student knows that L must be file:///C|/Documents%20and%20Settings/Jason%20Rafte. ..20Fall%202001%20-%20Hilfinger%20-%20Midterm%201.htm (1 of 7)1/27/2007 6:31:32 PM
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 61B, Midterm #1, Fall 2001 null. He tells you that he guesses this is caused by a problem with and asks you to help find it. Naturally, you want to be helpful. What would you say about his guess? d. I initialize two 2x2 arrays like this: int [] row = { 1, 2 }; int [][] A = { row, row }; int [][] B = { { 7, 5 }, { 3, 2 } }; and then I add B into A in place--that is, destructively like this: for (int i = 0; i < A.length; i+=1) for (int j = 0; j < A.length; j+=1) A[i][j] += B[i][j]; What do I get as result? e.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2009 for the course CS 61B taught by Professor Canny during the Spring '01 term at Berkeley.

Page1 / 7

Computer Science 61B - Fall 2001 - Hilfinger - Midterm 1 -...

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

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