mid2solns

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

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

View Full Document Right Arrow Icon
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!
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
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 09/15/2011 for the course CMPS 12A taught by Professor Mcdowell during the Winter '08 term at UCSC.

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 Right Arrow Icon
Ask a homework question - tutors are online