// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Integrate {
   public static double integrate(Integratable f, double x1, double x2) {
      double delta = (x2 - x1) / 10000;
      double res = 0.5 * delta * f.f(x1);
      for(int i = 1; i < 10000; i++) {
         res += delta * f.f(x1 + i * delta);
      }
      res += 0.5 * delta * f.f(x2);
      return res;
   }
   public static void main(String[] args) {
      for(int i = 0; i < 10; i++) {
         System.out.println(integrate(new CosIntegration(), 0, i/10.0) + " = " + Math.sin(i/10.0));
      }
   }
}

interface Integratable {
   public double f(double x);
}

class CosIntegration implements Integratable {
   public double f(double x) {
      return Math.cos(x);
   }
}
