Final.fa08

Final.fa08 - Signature cs11f Name Student ID CSE 11 Final...

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

View Full Document Right Arrow Icon
Signature _____________________ Name ________________________ cs11f ____ Student ID ____________________ CSE 11 Final Fall 2008 Page 1 ___________ (20 points) Page 2 ___________ (10 points) Page 3 ___________ (16 points) Page 4 ___________ (28 points) Page 5 ___________ (7 points) Page 6 ___________ (26 points) Page 7 ___________ (16 points) Page 8 ___________ (13 points) Page 9 ___________ (10 points) Total ___________ (146 points = 140 base points + 6 points EC [5%]) (100%)
Background image of page 1

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

View Full DocumentRight Arrow Icon
1 (Partial) Operator Precedence Table Operators Associativity * / % left to right + - left to right < <= > >= left to right == != left to right && left to right || left to right = right to left 1) Which of the following are not valid Java identifiers? (Circle your answer(s).) thirdLine 3rdLine line3 extends S.E. South East _SE_ Public 2) Using the operator precedence table above, evaluate each expression and state what gets printed. Remember short-circuit evaluation with && and ||. int i = 1, j = 2, k = 3, m = 2; System.out.println( j >= i && k == m ); ________ System.out.println( i >= 1 || j < 4 ); ________ System.out.println( !( k > m ) ); ________ System.out.println( !((i > 4) || (j <= 6)) == ((i <= 4) && (j > 6)) ); _________ 3) What gets printed? int a = 2, b = 7; System.out.println( -1 + ++a * 5 + 17 % 5 ); _________ System.out.println( 6 + b++ - 5 / 9 + 4 ); _________ 4) What gets printed? public class Question4 { public static void main( String[] args ) { final int MAX = 6; int i = -2, j = -3; for (i = 4; i < MAX; ++i ) { j = 5; while ( j <= MAX ) { System.out.println( i + " " + j ); ++j; } } System.out.println( i + " " + j ); } }
Background image of page 2
2 5) What gets printed as a result of the call F5( 3, -1 ) ? __________ public void F5( int a, int b ) { if ( (a > 0) && (b > 0) ) { if ( a > b ) { System.out.println( "A" ); } else { System.out.println( "B" ); } } else if ( (a < 0) || (b < 0) ) { System.out.println( "C" ); } else { System.out.println( "D" ); } } Give an example of values passed as arguments to F5() that would result in the method printing "D". F5( _____ , _____ ); 6) What value is returned as a result of the call a(6) to the method below? ________ public int a( int x ) { int local; if ( --x > 0 ) { local = a( x - 1 ) + x; return local; } else { return 0; } } Which of the following rewrites of this method are the same as the one above? A B C or All of them Circle your answer at the end of the line above. public int a( int x ) { if ( --x > 0 ) return a( x - 1 ) + x; else return 0; } public int a( int x ) { int local = 0; if ( --x > 0 ) local = a( x - 1 ) + x; return local; } public int a( int x ) { if ( --x > 0 ) return a( x - 1 ) + x; return 0; } A B C
Background image of page 3

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

View Full DocumentRight Arrow Icon
3 7) A bear is an animal and a zoo contains many animals, including bears. Three classes Animal, Bear, and Zoo are declared to represent animal, bear, and zoo objects. Which of the following is the most appropriate set of declarations? ________ A B class Animal extends Bear { . .. } class Bear extends Animal { . .. } class Zoo {
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/08/2011 for the course CSE cse21 taught by Professor Cs during the Fall '10 term at UCSD.

Page1 / 12

Final.fa08 - Signature cs11f Name Student ID CSE 11 Final...

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

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