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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:20:26+00:00 2026-06-12T13:20:26+00:00

I have a two dimensional array int matrix[numNodes][numArcs]. This is an Incidence matrix. Now,

  • 0

I have a two dimensional array int matrix[numNodes][numArcs]. This is an Incidence matrix.

Now, if we wish to add an arc, we have to check those nodes exist and the arc does not exist. This part works well. The following thing i need to do, is find an empty column to add the arc. So the matrix is full of zeros at the beginning . So its simple, you search each column until you find a column full of zeros. Sounds simple but its now working. This part of the code is the following:

    outerloop:
    for (int i = 0; i < numArcs; i++){
        for (int j = 0; j < numNodes; j++){
            if (matriz[j][i] != 0)
                break;
                //It finds a number != 0 so it should move to the next column 

            //If it gets here, the whole column was full of zeros
            column = i; 
            key = true;
            break outerloop;
        }
    }

I use the key to know i found the column, because if i dont its because the matrix is full and i need to duplicate it. Thats another issue non-related to this problem.

Now, i tried to figure out the problem and i notice the following: its only checking these positions:

01
02
03
03

As you can see, its just checking the first position of each column and not going all the way down how it should. To me it makes no sense. NumNode is 10 in my example, so it should go all the way down.

Edit:
My exact example
the matrix is like this:

 -1  -1 -1 0 0 0 ....
  0   1  0 0 0 ...
  0   0  1 0 0 .....

So when it reaches the fourth column, it reads that zero and return thats the empty column.
It does the same for the next n arcs I added. the following arcs i add don’t touch the first row any more.
thanks for the help

  • 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-12T13:20:28+00:00Added an answer on June 12, 2026 at 1:20 pm
    for (int i = 0; i < numArcs; i++){
        for (int j = 0; j < numNodes; j++){
            if (matriz[j][i] != 0)
                break;
                //It finds a number != 0 so it should move to the next column 
    
            //If it gets here, the whole column was full of zeros
            column = i; 
            key = true;
            break outerloop;
        }
    }
    

    What if in the inner loop, you don’t break for the first time.. You will store i into column without checking other rows for that column..

    You can better use a boolean flag variable to check what you want..

        int[][] matrix = new int[5][4];
        boolean columnEmpty = true;
        int column = 0;
        boolean key = false;
    
        matrix[0][0] = -1;
        matrix[0][1] = -1;
        matrix[1][1] = 1;
        matrix[1][2] = -1;
        matrix[2][2] = -1;
    
        outerloop: for (int i = 0; i < 5; i++){
                columnEmpty = true;
                for (int j = 0; j < 4; j++){
                    if (matrix[j][i] != 0) {
                       columnEmpty = false;
                       break;
                    }
    
                }
                if (columnEmpty) {
                    // If we are here.. then flag was never set to `true`. 
                    // So, all the rows for that column was Zero..
                    column = i; 
                    key = true;
                    break outerloop;
                }
    
            }
    
        System.out.println("Column : " + column);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two-dimensional array. When I print/dump this I get the following My
I have the following two dimensional array: static int[,] arr = new int[5, 5]
I have some problems using two dimensional array. static const int PATTERNS[20][4]; static void
I have declared my two dimensional array like this. But getting an error due
I have a two dimensional array having elements of a matrix I want to
I have a quadratic matrix(two-dimensional dynamic array of pointers) and need to change rows/columns
I have a two-dimensional array of ints, for example: int [][] board= { {23,17,3,29,12,10},
I have to add the sum of the rows of a two dimensional array
I have a two dimensional array with the following output Array ( [0] =>
I have a two dimensional array public class TwoDimensions { public static void main(String[]

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.