Final.fa09

Final.fa09 - Signature _ cs11f _ Name _ Student ID _ CSE 11...

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 2009 Page 1 ___________ (24 points) Page 2 ___________ (7 points) Page 3 ___________ (13 points) Page 4 ___________ (34 points) Page 5 ___________ (13 points) Page 6 ___________ (15 points) Page 7 ___________ (23 points) Page 8 ___________ (18 points) Page 9 ___________ (19 points) Total ___________ (166 points = 158 base points + 8 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 ! ++ -- (pre & post inc/dec) right to left * / % 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).) 1stJavaClass My_First_Java_Class Java1 CSE11Is#1 CSE11 CSE-11 My1stJavaClass double 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( !( k >= m ) ); ________ System.out.println( j <= i || j == m && k <= m ); ________ System.out.println( i >= 1 && !(j != 4) ); ________ System.out.println( !(i > 4 && j <= 6) == i >= 4 || j > 6 ); ________ 3) What gets printed? int a = 3, b = 6; 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 = 9; int i = 4, j = 8; for (i = 6; i <= MAX; ++i ) { j = i; while ( j < MAX ) { --j; System.out.println( i + " " + j ); j += 2; } } System.out.println( i + " " + j ); } }
Background image of page 2
2 5) What gets printed as a result of the call F5( -1, 3 ) ? __________ public void F5( int a, int b ) { if ( (a >= 0) || (b <= a) ) { 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" ); } } Using only the values -2 and -1, give an example of values passed as arguments to F5() that would result in the method printing "B". The values -2 and -1 can be in any order and may be repeated (you do not need to use both values – both arguments may be the same value). F5( _____ , _____ ); 6) Assume the following code is defined: public class NumberHolder { private int number; public NumberHolder() { this.number = 0; } public void setNum(int n) { this.number = n; } public int getNum() { return this.number; } } What is the output of the following code using the above class definition? NumberHolder a = new NumberHolder(); a.setNum( 5 ); NumberHolder b = a; System.out.println( a.getNum() + " " + b.getNum() ); _____________ b.setNum( 2 ); System.out.println( a.getNum() + " " + b.getNum() ); _____________
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) Given the following class definitions: public class Person { public Person() { . .. } public void print() { System.out.println( "Person" ); } public void printAll( Person[] list )
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.

Page1 / 12

Final.fa09 - Signature _ cs11f _ Name _ Student ID _ CSE 11...

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