Midterm2b example

Midterm2b example - CMPS 12A Winter 2002 Midterm 2 March 5...

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

1 CMPS 12A - Winter 2002 Midterm 2 March 5, 2002 Name:__________________________________________ID:___________________________b This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However, I just want code fragments, you must not write extra code such as a class specification or extraneous print statements. 1. [10 points] Given the following javadoc specification, show how to call and get a return value from the function pow() . Let x equal 5, y equal 3, and store the result in z . Print out the value that is returned. static double pow(double x, double y) Returns of value of the first argument raised to the power of the second argument. double x, y, z; 2 points x = 5; 1 point y = 3; 1 point z = pow(x, y); 4 points System.out.println(z); 2 points 2. [10 points] Write a method called areaOfCircle() that takes as a parameter the radius of a cir- cle and returns its area. public static double areaOfCircle(double radius) { 3 points (return type, name, parame- ter) double area; 2 points area = Math.PI * radius * radius; 3 points return area; 2 points }

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

View Full Document
2 3. [10 points] Given the following numbered lines of code 1 class Foo { 2 3 public static void main(String[] args) { 4 int e = 5; 5 6 for(int d = 0; d < 100; d++) { 7 d = e*d; 8} 9 10 int c; 11 12 c = foo(e); 13 14 System.out.println(c); 15 } 16 17 public static double foo(int b) { 18 double a = 1/b; 19 return a; 20 } 21 }
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

Midterm2b example - CMPS 12A Winter 2002 Midterm 2 March 5...

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

View Full Document
Ask a homework question - tutors are online