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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:17:22+00:00 2026-05-26T13:17:22+00:00

I’ve been battling with this for some time and seem to be getting nowhere.

  • 0

I’ve been battling with this for some time and seem to be getting nowhere. The set up is so; I have a 2D array. For this array I need to iterate through each value and return the diagonal neighbours (5 values). These neighbours will be put into a new 1D [5] array and bubblesorted. The middle value (median) will then be returned and put into a new array of medians.

So far I have methods for extracting the diagonal neighbours:

    //get diagonals from original DEM

    double [] getDiagonals(int i, int j) {

        double [] tempArray = new double [5];

        tempArray[0] = data[i -1][j +1];
        tempArray[1] = data[i -1][j -1];
        tempArray[2] = data[i][j];
        tempArray[3] = data[i +1][j -1];
        tempArray[4] = data[i +1][j +1];


        return tempArray;
    }

I’ve then used this method in an iteration to get diagonals for each value in the original array:

        //get diagonals for each 

    double [] []   bubbles(){

        double [] [] datap = new double [298] [298];

        for (int i = 1; i < data.length; i++){
            for (int j = 1; j < data[i].length; j++) {
                if ((i > 0) && (j > 0)) {
                    if ((i < data.length-1) && (j  < data.length-1)){

                         double [] tempArray = getDiagonals(i, j);
//do something with the tempArray

I think this is where I’m coming unstuck. Through testing the getDiagonals method works fine. I’m struggling to get the tempArray out of the bubbles() method. If I set the output to be the tempArray it only returns the 5 values calculated for the bottom right corner of the original array.

I’ve tried calling other methods into the bubbles() method in order to do all the processing there and return a new array:

    //get diagonals for each 

    double [] []   bubbles(){

        double [] [] datap = new double [298] [298];

        for (int i = 1; i < data.length; i++){
            for (int j = 1; j < data[i].length; j++) {
                if ((i > 0) && (j > 0)) {
                    if ((i < data.length-1) && (j  < data.length-1)){

                         double [] tempArray = getDiagonals(i, j);
                         double sorted [] = sort(tempArray);
                         double median = sorted[2];


                            for (int z = 0; z < datap.length; z++){
                                for (int y = 0; y < datap[z].length; y++){
                                datap[z][y] = median;
                                }
                            }   



                    }
                }   
            }
        }
        return datap;
    }

Again this fails and the output datap is just zeros. The sort() method above passed out the diagonals to a bubble sort method (which I know works on its

I guess my question is how to process within a method that is iterating and populate a new array?

I hope this makes sense but if you need more details please let me know. And yes, the sort I’m using is a bubble sort. I know they are rubbish but this is for a course I’m doing so it has to be used. And yes, I’m pretty new to java.

Any help would be greatly appreciated (and I’ll even reference you if I need to use some code you provide 😉

  • 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-26T13:17:23+00:00Added an answer on May 26, 2026 at 1:17 pm

    Finally cracked it. To populate the whole array the following code works a peach.

    //Diagonal to 1dArray and sorting
    
    double [] [] bubbles()
    {
        double [][] tempArray = new double [300][300];
    
        int y = 0;
        int z = 0;
        double median = 0;
    
        for (int i = 0; i < data.length; i++)
        {
            for (int j = 0; j < data[i].length; j++)
            {
                if ((i > 0) && (j > 0))
                {
                    if ((i +1 < data[i].length) && (j +1 < data[j].length))
                    {
                        double [] diagonals = getDiagonals(i, j);
    
                        //Need to sort here
                        median = diagonals[2];
                        tempArray[i][j] = median;
                    }
                }
            }
        }
        return tempArray;
    }
    

    The sorting was taken out and I haven’t tested with it back in yet; but so far this is providing new values for all the cells in the temp array.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put

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.