I have written this code to find the cycle in graph

 public boolean hasCycle(int i, int[][] mat) {

        visited[i] = 1;
        // for( int i = 0; i < numNodes; i++ )
        for (int j = 1; j < mat.length; j++) {
            if (mat[i][j] == 1 && i != j) {
                if (visited[j] == 1)
                    return true;
            } else if (hasCycle(j, mat))
                return true;

        }

        return false;
    }

But it is not giving correct result. Can anyone help?

"it is not giving correct result" tells us nothing. If you have a compiler or runtime error message post the complete message plus the actual code it refers to. If your code is giving an incorrect result explain what result you get and what the correct result should be.

hey the programe you have writen for the Car.class was that free of error i want to know about that prorame i have done my own but your programe is bit easy to undrstand
(Skyyadav)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.