0

Hello,

I have a file and this it how it looks like:

6
{a, b, c, d, e, f}
1 1 1 0 0 0
0 1 1 0 0 0
0 0 1 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
1 1 1 1 1 1

6 is the number of elements in the set and {a, b, c, d, e, f} is the list of set members and the matrix is the relation matrix.


I read the file into 2-D array with no problems but I want to check if the matrix is transitive or not. This is how to check :

If Mij=Mjk = Mik

I implemented a method to check it but the output is always transitive !

public static boolean CheckTransitive(int array[][])
   	{

		boolean check=true;

		while(check==true)
		{

		    	for(int i=0;i<array.length;i++)
		    		{
		    		for( int j =0;j<array[i].length;j++)
		    			{
		    			for( int k =0;k<array[j].length;k++)
		    				{

		    				if (array[i][j]==array[j][k]){
						  if(array[i][j]!=array[i][k]){
					 	             check=false;
					 		     break;

								}

		    				}

    					}break;
   				}break;

		    	}break;
  	 }
  	 if(check==true){
  	 	return true;

  	 }else{
  	 	return false;
  	 }


	}

Could any one please tell me why the output is always transitive (true) ! and where is exactly the wrong in my code ?

Thanks in advance :)

Edited by matrixcool: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by zeroliken
0

try to trace the program on the loop containing k as the counter
the value of check must be still equal to true cause after that loop you break the statement before that and then you break the statement before that...until you break the while loop

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.