Question

In: Computer Science

A JAVA program that will read a boolean matrix corresponding to a relation R and output whether R is Reflexive, Symmetric, Anti-Symmetric and/or Transitive.

A JAVA program that will read a 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 the size n of an n x n boolean matrix followed by the matrix elements. Document your program nicely.
NOTE: The program must output a reason in the case that an input relation fails to have a certain property.

Solutions

Expert Solution

package org.rohit.practice;

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;

System.out.println("Please Enter n*n Matrix containing : ");

System.out.println("Please enter size of Matrix: ");

Scanner s=new Scanner(System.in);

n=s.nextInt();

System.out.println("Please enter the elements of Matrix: ");

for(i=0;i

for(j=0;j

a[i][j]=s.nextBoolean();

}

}

for(i=0;i

for(j=0;j

//Checking for Reflexive

if(i==j && a[i][j]==false){

reflexive=false;

}

//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 all a[x][x] are 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");

}

}

}


Related Solutions

A JAVA program that will read a boolean matrix corresponding to a relation R and output...
A JAVA program that will read a 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 the size n of an n x n boolean matrix followed by the matrix elements. Document your program nicely. NOTE: The program must output a reason in the case that an input relation fails to have a certain property.
Let R be a relation on a set that is reflexive and symmetric but not transitive?...
Let R be a relation on a set that is reflexive and symmetric but not transitive? Let R(x) = {y : x R y}. [Note that R(x) is the same as x / R except that R is not an equivalence relation in this case.] Does the set A = {R(x) : x ∈ A} always/sometimes/never form a partition of A? Prove that your answer is correct. Do not prove by examples.
Determine whether the relation R on the set of all people is reflexive, symmetric, antisymmetric, and/or...
Determine whether the relation R on the set of all people is reflexive, symmetric, antisymmetric, and/or transitive, where (a, b) ∈ R if and only if a) a is taller than b. b) a and b were born on the same day.
Determine whether the relation R on the set of all real numbers is reflexive, symmetric, antisymmetric,...
Determine whether the relation R on the set of all real numbers is reflexive, symmetric, antisymmetric, and/or transitive, where (x,y) ∈ R if and only if: a) x = 1 OR y = 1 b) x = 1 I was curious about how those two compare. I have the solutions for part a) already.
Determine whether the relations described by the conditions below are reflexive, symmetric, antisymmetric or transitive on...
Determine whether the relations described by the conditions below are reflexive, symmetric, antisymmetric or transitive on a set A = {1, 2, 3, 4} All ordered pairs of (x, y) such that x   not Equal   y. All ordered pairs of (x, y) such that y > 2. All ordered pairs of (x, y) such that x = y ± 1. All ordered pairs of (x, y) such that x = y2. All ordered pairs of (x, y) such that x...
Write a Java program to 1. read in the size of a square boolean matrix A...
Write a Java program to 1. read in the size of a square boolean matrix A 2. read in the 0-1 matrix elements 3. read in a positive integer n 4. display A^n
Write a Java program to 1. read in the size of a square boolean matrix A...
Write a Java program to 1. read in the size of a square boolean matrix A 2. read in the 0-1 matrix elements 3. read in a positive integer n 4. display A^n Multiplying that matrix to the nth power. Like A^2 = matrix A * matrix A. Elements ONLY can be 0 or 1.
Argue with proof that whether following asymptotic notations are transitive, reflexive, or symmetric. O(n); o(n); Ω(n);...
Argue with proof that whether following asymptotic notations are transitive, reflexive, or symmetric. O(n); o(n); Ω(n); ω(n); ϴ(n)
Program using java Take user input and give corresponding output. A user is considering different options...
Program using java Take user input and give corresponding output. A user is considering different options of operating air conditioning. Depending on room temperature (here, room temperature is given by user), this program should give different instructions. There are three scenarios. - If temperature is above 90, the program should output “cooling”. -If the temperature is below 70, the program should output “heating”. -Otherwise, the program should output “stopped”. For example, if user enters “95”, this is how the program...
Java Program. Please read carefully. i need the exact same output as below. if you unable...
Java Program. Please read carefully. i need the exact same output as below. if you unable to write the code according to the question, please dont do it. thanks To the HighArray class in the highArray.java program (Listing 2.3), add the following methods: 1.      getMax() that returns the value of the highest key (value) in the array without removing it from the array, or –1 if the array is empty. 2.      removeMax() that removes the item with the highest key from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT