1. Consider these Java functions: public static double f(double x) { return g(x)
ID: 3760444 • Letter: 1
Question
1. Consider these Java functions:
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 function calls:
a. double x1 = f(2);
b. double x2 = g( h(2) );
c. double x3 = k(g(2) + h(2) );
d. double x4 = f(0) + f(1) + f(2);
e. double x5 = f(-1) + g(-1) + h(-1) + k(-1);
Explanation / Answer
a. double x1 = f(2); //x1=39.0
b. double x2 = g( h(2) ); // x2=400.0
c. double x3 = k(g(2) + h(2) ); // x3=92.0
d. double x4 = f(0) + f(1) + f(2); // x4=62.0
e. double x5 = f(-1) + g(-1) + h(-1) + k(-1); // x5=0.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.