




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Java programming exercises from the cs 61b course taught by hilfinger during spring 2006. The exercises cover various topics such as arrays, strings, classes, and iterators. Students are required to write code to solve compilation and runtime errors, identify the outcome of executing given code snippets, and determine if certain assertions are true or false.
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





CS 61B, Spring, 2006, Hilfinger
Code Result d. class Thing { int x; "equal" – the equals method returns true public Thing( int x ) { this.x = x; } public boolean equals( Object p ) { return x == ((Thing) p).x; } public static void main(String[] args) { Thing p1 = new Thing(3), p2 = new Thing(3); if( p1.equals( p2 )) System.out.println("equal"); else System.out.println("not equal"); } } e. class Thing { int x; runtime error – cannot cast "(3)" to Thing public Thing( int x ) { in equals method. this.x = x; } public boolean equals( Object p ) { return x == ((Thing) p).x; } public static void main(String[] args) { Thing p1 = new Thing(3); if( p1.equals( "(3)" )) System.out.println("equal"); else System.out.println("not equal"); } }
private List
c. Assuming that next and hasNext on Powerset iterators take constant time, what is the worst-case time for subsetSum (Be as precise as possible). n2n −^1 n where n is ints.size()
/* b. / /* A list that is identical to L, except that the first