mid2solns

# mid2solns - CMPS 12A Introduction Programming Winter 2008...

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

CMPS 12A Introduction Programming Winter 2008 Midterm Exam 2 Solutions 1. (20 Points) Trace the following Java program and place the output on the lines below exactly as it would appear on the screen. (Note more lines are printed than you actually need.) Notice also that the method fcn2() is overloaded, so there are really three distinct functions here. To tell which version of fcn2() is called, match the types in the argument list with the types in the parameter list. // problem1.java class problem1{ public static void main( String[] args ){ int a=5, b=3, c; double x=2.2, y=1.3, z; c = fcn1(a, b); b = fcn2(x, y); z = fcn2(c, b); System.out.println("a="+a+", b="+b+", c="+c); System.out.println("x="+x+", y="+y+", z="+z); System.out.println("bye!"); } static int fcn1(int i, int j){ i++; ++j; return (i+j-1); } static int fcn2(double u, double v){ return fcn1((int)(u+v), 3); } static double fcn2(int r, int s){ return (double)fcn1(r+s, 3); } } Output: a=5, b=7, c=9 x=2.2, y=1.3, z=20.0 bye!

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

View Full Document
2. (20 Points) Determine the output of the following Java program, and place it on the lines below exactly as it would appear on the screen. (Hint: first figure out exactly what the recursive method
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

mid2solns - CMPS 12A Introduction Programming Winter 2008...

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

View Full Document
Ask a homework question - tutors are online