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 :)

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

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.