Midterm2a example

Midterm2a example - CMPS 12A - Winter 2002 Midterm 2 March...

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

View Full Document Right Arrow Icon
1 CMPS 12A - Winter 2002 Midterm 2 March 5, 2002 Name:__________________________________________ID:____________________________ 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 a equal 5, b equal 3, and store the result in c . Print out the value that is returned. static double pow(double a, double b) Returns of value of the first argument raised to the power of the second argument. double a, b, c; 2 points a = 5; 1 point b = 3; 1 point c = pow(a, b); 4 points System.out.println(c); 2 points 2. [10 points] Write a method called circleArea() that takes as a parameter the radius of a circle and returns its area. public static double circleArea(double radius) { 3 points (return type, name, parame- ter) double area; 2 points area = Math.PI * radius * radius; 3 points return area; 2 points }
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 3. [10 points] Given the following numbered lines of code 1 class Foo { 2 3 public static void main(String[] args) { 4 int a = 5; 5 6 for(int b = 0; b < 100; b++) { 7 b = a*b; 8} 9 10 int c; 11 12 c = foo(a); 13 14 System.out.println(c); 15 } 16 17 public static double foo(int d) { 18 double e = 1/d; 19 return e; 20 } 21 }
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 03/19/2012 for the course MATH MATH 304 taught by Professor Young during the Spring '09 term at Texas A&M.

Page1 / 6

Midterm2a example - CMPS 12A - Winter 2002 Midterm 2 March...

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