title: Lagrange interpolation in JAVA
body: <p>I have done a search around, but there isnt any code available in java hence I have write my own and I have encountered some issue. I actually got this code from a c++ source and trying hard to convert it into a workable java program. </p>
  
  <blockquote>
    <p><a href="http://ganeshtiwaridotcomdotnp.blogspot.sg/2009/12/c-c-code-lagranges-interpolation.html" rel="nofollow">http://ganeshtiwaridotcomdotnp.blogspot.sg/2009/12/c-c-code-lagranges-interpolation.html</a></p>
  </blockquote>
  
  <pre><code>public static void main(String[] args) {
  
      int n;
      int i, j;
      int a;
      int x[] = null;
      int f[] = null;
      int sum = 0;
      int mult;
      Scanner input = new Scanner(System.in);
      System.out.println("Enter number of point: ");
      n = input.nextInt();
  
      System.out.println("Enter value x for calculation: ");
      a = input.nextInt();
  
      for (i = 0; i &lt; n; i++) {
  
          System.out.println("Enter all values of x and corresponding functional vale: ");
          x = input.nextInt();
          f = input.nextInt();
      }
  
      for (i = 0; i &lt;= n - 1; i++) {
          mult = 1;
          for (j = 0; j &lt;= n - 1; j++) {
  
              if (j != i) {
                  mult *= (a - x[j]) / (x[i] - x[j]);
  
              }
              sum += mult * f[i];
          }
  
      }
      System.out.println("The estimated value of f(x)= " + sum);
  
  }
  </code></pre>