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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:52:52+00:00 2026-06-15T16:52:52+00:00

I am trying to write a piece of Java code which can deduce a

  • 0

I am trying to write a piece of Java code which can deduce a 1D integer array from a 2D integer array. My 2D array looks something like this:

Node1  Node2   Path
 6      8      501
 2      6      500 
 8      10     505 
 2      4      502

And my task is as follows. I want to find “Path”s from elements of the first column (Node 1) to the elements of the second column (Node2). I mean something like these:

Path from “2” to “8” would be 500 501 in that order. And path from “2” to “4” would be 502 (not 500 since it terminates at “6”)

I have been trying to achieve this by iterating with simple for loop but have been struggling. Could someone please let me know how I can solve this?

The code snippet which I am trying to write to achieve is this:

            PathSequence:
            for(int i = 0; i < PathGraphRow; i++){
                if(PathGraph[i][0] == source){
                    if(i==0)
                    {
                        nextNode = PathGraph[i][1];
                        resultantPaths[counter] = PathGraph[i][2];
                        prev = lightPathGraph[i][2];
                        if(nextNode == dest){
                            break PathSequence;
                        }
                        counter++;
                    }else if(i > 0 && prev != PathGraph[i][2])
                    {
                        nextNode = PathGraph[i][1];
                        resultantPaths[counter] = PathGraph[i][2];
                        prev = PathGraph[i][2];
                        if(nextNode == dest){
                            break PathSequence;
                        }
                        counter++;
                    }
                }

                if(nextNode == PathGraph[i][0] && prev != PathGraph[i][2]){
                    nextNode = PathGraph[i][1];
                    resultantPaths[counter] = PathGraph[i][2];
                    prev = PathGraph[i][2];
                    if(nextNode == dest){
                        break PathSequence;
                    }
                    counter++;                    
                }

                if(i == PathGraphRow-1 && PathGraph[i][2] != resultantPaths[counter]){
                    if(PathGraph[i][1] != dest){
                        resultantPaths = new int[PathCount];
                    }
                }

            }        
    }

Thank you.

Regards

  • 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-15T16:52:53+00:00Added an answer on June 15, 2026 at 4:52 pm

    Unless I’m overlooking some details the problem is fairly trivial without the sub paths. You just need a single for loop that is very specific.

     for (int i = 0; i < columns; i++)
     {
          Path path = new Path(array[i][0], array[i][1], array[i][2]);
          pathsArray.Add(path);
     }
    

    That is of course pseudo code, but that’s basically how I would do it. I would make each path a three tuple. I still don’t quite get how you intend to store the data, if you put all the values in a 1D int array, how do you know where a path starts and ends? Assuming all paths are defined by a start, end, and result that would work in a 1D array although it would be worse to use than the 2D array. If paths are of arbitrary length there’s no way to store the data in a 1D array. Anyways, here’s code to put the table provided in a 1D array (assuming no greater complexity);

    int[] paths = new int[2dArray.length * 3];
    int mapper = 0;
    
    for (int i = 0; i < 2dArray.length; i++)
    {
         paths[mapper] = 2dArray[i][0];
         paths[mapper + 1] = 2dArray[i][1];
         paths[mapper + 2] = 2dArray[i][2];
         mapper += 3;
    }
    

    Then to access the array you need to do a bunch of mod 3 crap to know which value you’re getting…

     if (index % 3 == 0)
        //path start
     else if (index % 3 == 1)
        //path end
     else if (index % 3 == 2)
        // result of path 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a piece of code in which I can see
I'm trying to write a piece of code which use the user choice in
I'm trying to write a small piece of code that merges lines alternatively from
Am trying to write a piece of code which will allows the user to
I am trying to write a piece of code that can parse any xml
I'm trying to write a piece of code which receives a string, uses the
I'm trying to write some xml by this piece of code docs = XmlReportGenerator()
I'm trying to write some xml by this piece of code docs = XmlReportGenerator()
I was trying to write a piece of Java code to read each line
I'm trying to write out a piece of code that can reduce the LENGTH

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.