0

part of my program includes my boolean 2d array: boolean[][] matrix = new boolean[V][V];i want to iterate through the vertex and check if it is true but am getting error: cannot convert from boolean[] to boolean. casting (boolean) does not help. i have also tried boolean[v][w] == true.
here is where i am having the problem:

public int degree(int v) {
        int degreeCounter = 0;
        for(int i = 0; i < v; i++){
            if(matrix[v]){ //<---- problem here!
                degreeCounter++;
            }
        }
        return degreeCounter;
    }

Any insight is greatly appreciated!

Edited by Roger_2

2
Contributors
1
Reply
7
Views
1 Year
Discussion Span
Last Post by JamesCherrill
1

matrix is a 2D array (strictly: an array of arrays) so you need two indexes to get to a single element in matrix. I don't know excatly what you tried, but you will need something like
if (matrix[i][j]) ...
where i and j are integers, integer expressions, or anything else that the compiler can convert to int.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.