implementing jacobi algorithm to implement laplace equation
<p>The Algorithm traverses a 2D NxN array, making every element the average of its 4 surrounding neighbors (left, right, top, down).</p>

<p>The NxN array has initially all zeros and is surrounded by a margin with all 1’s as shown in
the example below. The 1’s never change, and the 0’s increase little by little.</p>

<pre><code>             1 1 1 1 1 1 1 1
             1 0 0 0 0 0 0 1
             1 0 0 0 0 0 0 1
             1 0 0 0 0 0 0 1
             1 0 0 0 0 0 0 1
             1 0 0 0 0 0 0 1
             1 0 0 0 0 0 0 1
             1 1 1 1 1 1 1 1
</code></pre>

<p>I have implemented the following code and and am getting array index out of bounds exception . pls correct me .</p>

<pre><code>my code :
       public class Main {
static int NO_OF_THREADS =8;

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
      Jacobi jacobi = new Jacobi(NO_OF_THREADS);
      jacobi.initialize();
      jacobi.create_threads();
    }

  }//end of Main class

  public class Jacobi {
int ROWS=1000,COLS=1000;
private int i;
private int upper=100;//prevents buffer overflow
private int lower=99;//prevents buffer overflow
private int j;
private double[][] jacobi=new double[ROWS][COLS];
private int NO_OF_THREADS;


public Jacobi(int k)
{
    NO_OF_THREADS=k;
}

public  void initialize() {
        for(i=1;i&lt;=upper;i++)
           {
           for(j=1;j&lt;=upper;j++)
                 {

                       if((i==1)||(i==upper)||(j==1)||(j==upper)){
                      jacobi[i][j]=1.0;
                       }

                   else
                          jacobi[i][j]=0.0;


                 }

             }

    }
              public double[][] getJacobi()
              {
                    return jacobi;
              }

              public void create_threads()
              {
                   theThread[] threads=new theThread[NO_OF_THREADS];
                   for(int k=1;k&lt;=NO_OF_THREADS;k++)
                   {
                       threads[k]=new theThread();
                       threads[k].start();
                    }
               }
               //Inner class of Jacobi

             class theThread extends Thread {

               @Override
              public void run()
              {
                   for(int q=2;q&lt;=lower;q++)
                   {

                     System.out.println("The ID of this thread is: "+getName());
                     for(int j=2;j&lt;=lower;j++)
                      {
                        synchronized(Jacobi.this)
                         {

                        jacobi[q][j]=(jacobi[q-1][j]+jacobi[q+1][j]+jacobi[q] [j-1]+jacobi[q][j+1])/4;
                         }//end of synchronized
              }//end of inner for loop


          }//end of for loop
     }
}//end of theThread class
}//end of jacobi class
</code></pre>
