Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 827597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:36:00+00:00 2026-05-15T03:36:00+00:00

The Algorithm traverses a 2D NxN array, making every element the average of its

  • 0

The Algorithm traverses a 2D NxN array, making every element the average of its 4 surrounding neighbors (left, right, top, down).

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.

             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

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

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<=upper;i++)
           {
           for(j=1;j<=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<=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<=lower;q++)
                   {

                     System.out.println("The ID of this thread is: "+getName());
                     for(int j=2;j<=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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:36:02+00:00Added an answer on May 15, 2026 at 3:36 am

    In the line

    int ROWS,COLS=1000;
    

    I think you want to change that to

    int ROWS=1000, COLS=1000;
    

    otherwise ROWS isn’t set up correctly…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 425k
  • Answers 425k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Array derefencing from function calls isn't supported by PHP. It's… May 15, 2026 at 12:27 pm
  • Editorial Team
    Editorial Team added an answer Buffers are global to the Vim instance, not confined to… May 15, 2026 at 12:27 pm
  • Editorial Team
    Editorial Team added an answer Often there is one endpoint for every web application. So… May 15, 2026 at 12:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.