Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ALL I NEED IS A MODIFICATION TO THIS JAVA CODE SO IT WILL OUTPUT WHY THE MATRIX FAILS ONE OF THE FOUR PROPERTIES (REFLEXIVE, SYMMETRIC,

ALL I NEED IS A MODIFICATION TO THIS JAVA CODE SO IT WILL OUTPUT WHY THE MATRIX FAILS ONE OF THE FOUR PROPERTIES (REFLEXIVE, SYMMETRIC, ANTI-SYMMETRIC, TRANSITIVE). Q: Write a program that will read in the boolean matrix corresponding to a relation R and output whether R is reflexive, symmetric, anti-symmetric and/or transitive. Input to the program will be: 1. the size 'n' of an nxn boolean matrix followed by 2. the matrix elements. NOTE: The program must output a reason as to why the matrix is not reflexive or symmetric or anti symmetric or transitive. Part of the solution code is here but it does not provide why the matrix fails a property.

package xyz;

import java.util.Scanner;

public class Relation {

public static void main(String[] args) {

boolean a[][]=new boolean[50][50];

boolean reflexive=true,transitive=true,symmetric=true,anti=true;

int n,i,j,count=0; Scanner s=new Scanner(System.in);

System.out.println("Please enter a number for size n of the n*n matrix: ");

n=s.nextInt();

System.out.println("Please enter the elements of Matrix row wise, one by one by hitting enter: ");

for(i=0;i for(j=0;j a[i][j]=s.nextInt()!=0; } }

for(i=0;i for(j=0;j

//Checking for Reflexive if(i==j && a[i][j]==false){ reflexive=false; } //else{ //System.out.println(a[i][j]);} //Checking for Symmetric if(i != j && ((a[i][j]== true && a[j][i]==false) || (a[i][j]== false && a[j][i]==true))){ symmetric=false; }

//Checking for Transitive if(i != j && (a[i][j] != a[j][i]) && (a[i][j] != a[i][i])){ transitive=false; }

//Checking for Anti Symmetric if(i!=j && a[i][j]==true){ anti = false; } } }

//Printing the final Output System.out.println("Relation is: "); if(reflexive == false){ System.out.println("Not reflexive as" +" is not true."); }else{ System.out.println("Reflexive"); }

if(transitive == false){ System.out.println("Not Transitive as if a[x][y] = a[y][x] = true then a[x][x] is false."); }else{ System.out.println("Transitive"); }

if(symmetric == false){ System.out.println("Not Symmetric as if a[x][y] is true then a[y][x] is false."); }else{ System.out.println("Symmetric"); }

if(anti == false){ System.out.println("Not Anti Symmetric as if a[x][y] = a[y][x] = true then x is not equals to y."); }else{ System.out.println("Anti Symmetric"); } } }

ALL I NEED IS A MODIFICATION TO THIS JAVA CODE SO IT WILL OUTPUT WHY THE MATRIX FAILS ONE OF THE FOUR PROPERTIES (REFLEXIVE, SYMMETRIC, ANTI-SYMMETRIC, TRANSITIVE). Please test it with the following two matrices and provide a screenshot of the solution. 010 0101 011 1010 110 0101 ..... 1010

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions