|
Second Summer 2002 |
Questions:
double parameter and a double return value.
int parameter and a double return value.
int parameter and a String return value.
double parameters and a boolean return value.
int return value.
Ellipse2D.Double parameter and a double return
value.
Line2D.Double parameter and a Point2D.Double
return value.
return statement
return statement
void never has a return statement
return statement, the method exits immediately
void always has a side effect.
public static double sqrt(double x) public static Point2D.Double midpoint(Point2D.Double a, Point2D.Double b) public static double area(Ellipse2D.Double c) public static String romanNumeral(int n) public static double slope(Line2D.Double a) public static boolean isLeapYear(int year) public static String weekday(int day)
public static double f(double x)
{
return g(x) + Math.sqrt(h(x));
}
public static double g(double x) { return 4 * h(x); }
public static double h(double x) { return x * x + k(x) - 1; }
public static double k(double x) { return 2 * (x + 1); }
Without actually compiling and running a program, determine the
results of the following method calls:
double x1 = f(2); double x2 = g(h(2)); double x3 = k(g(2) + h(2)); double x4 = f(0) + f(1) + f(2); double x5 = f(-1) + g(-1) + h(-1) + k(-1);
boolean. Give an example of a predicate method and an
example of how to use it.
main
method and a program?
Math.sqrt Math.tan Math.log Math.exp Math.pow Math.abs
public static void falseSwap(double a, double b)
{
double temp = a;
a = b;
b = temp;
}
public static void main(String[] args)
{
double x = 3;
double y = 4;
falseSwap(x, y);
System.out.println(x + " " + y);
}
Why doesn't the method swap the contents of x and y?
Point2D.Double.
Here's where the solutions are.