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 8751007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:57:55+00:00 2026-06-13T12:57:55+00:00

So I need to take a 2D array do calculations to each elements and

  • 0

So I need to take a 2D array do calculations to each elements and transfer that into another 2D array while using the values to the “left” “right” “up” and “down” of the current element. If the current element is on the edge (x = 0, y = 0, x = array.length , y = array.length) I will get an array out of bounds error. I want to create a for loop that deals with each of those cases but I don’t know how to do it. A sample of my code is

private void buildE(int[][] array, int y, int x)
{

    int up = array[y - 1][x];
    int down = array[y + 1][x];
    int left = array[y][x - 1];
    int right = array[y][x + 1];

    if(up == 0){

        buildETopRow(array);

    }

E will be my new array. This method does not work because y does not equal 0, it just doesn’t exist but I can’t set ints to null either. In the case of an out of bounds error I need the element (up, down, left, or right) that is out of bounds to equal the current element. Is there a way I can still use a for loop for this or do I need to do something else?

  • 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-06-13T12:57:56+00:00Added an answer on June 13, 2026 at 12:57 pm

    If I read this correctly you want to effectively treat the difference of an element on the edge with an element off the edge as 0. If that’s true I would write four methods right(), left(), up() and down(), with down() shown below as an example:

     /*
      * Return the difference between an element an the element below it
      */
    
    public void down(int x, int y) {
    
        if (y == array.length - 1) { 
           \\ on the bottom edge
           return 0;
        }   
    
        return array[y][x] - array[y + 1][x];
    
    }
    

    And inside your loop you’d calculate:

    up(x,y) + down(x,y) + right(x,y) + left(x,y)
    

    or whatever calculation it is you need to sum up.

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

Sidebar

Related Questions

I need to take an array that looks something like ... array( 11 =>
I need to compare a 1-dimensional array, in that I need to compare each
I need to take an array of data called @users and turn it into
I need to take a char [] array and copy it's value to another,
I have an int[] array. I need to take an int and append it
Waht i need to do is take a single dimensional array, ie: [1, 1,
I need to take offline and offline JOBS of schema B while I'm logged
I need to take a C++ vector with potentially a lot of elements, erase
I need to take a csv file and import this data into a multi-dimensional
I have a multidimensional array. I need a function that checks if a specified

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.