public class Integration2 { public static void main (String[] argv) { // We'll compute f(x) at x=1, 2, ..., 10 and put that in a graph. Function F = new Function ("f"); // Notice: we are computing f(1), f(2), ..., and NOT f(d), f(2d), ... for (double x=1; x<=10; x+=1) { // Our method compute_f() does all the dirty work. double f = compute_f (x); F.add (x, f); System.out.println ("x=" + x + " f(x)=" + f); } // Display. F.show (); } static double compute_f (double x) { // The value of d is fixed throughout. double d = 0.01; // Initial value is assumed known: double f = 0; // Compute for x-values in [0,10]. We are now using a variable called z. // Notice: goes over the range 0.01 up through x (which is input to the method). for (double z=0.01; z<=x; z+=0.01) { // We are given g, so we can compute it. double g = 6 * z; // Find the new value at f(z+d) that becomes the new f. f = f + d * g; // No need to print intermediate values. } // Return f(x) return f; } }