Question

In java please

Program 5.1: Properties of a Relation Write a program that can determine which, if any, of the following properties a binary

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package abc;

public class Main {
  
   // Fills transpose of mat[4][4] in tr[4][4]
   static void transpose(int mat[][], int tr[][])
   {
   for (int i = 0; i < 4; i++)
   for (int j = 0; j < 4; j++)
   tr[i][j] = mat[j][i];
   }
  
   static // Returns true if mat[][N] is symmetric, else false
   boolean isSymmetric(int mat[][])
   {
   int tr[][] = new int[4][4];
   transpose(mat, tr);
   for (int i = 0; i < 4; i++)
   for (int j = 0; j < 4; j++)
   if (mat[i][j] != tr[i][j])
   return false;
   return true;
   }
  
   static boolean isAntiSymmetric(int mat[][])
   {
   int tr[][] = new int[4][4];
   transpose(mat, tr);
   for (int i = 0; i < 4; i++)
   for (int j = 0; j < 4; j++)
   if (mat[i][j] != -tr[i][j])
   return false;
   return true;
   }
  
   static boolean isReflexive(int mat[][])
   {
   for (int i = 0; i < 4; i++) {
       for (int j = 0; j < 4; j++) {
           if (i==j) {
               if(mat[i][j] == 1){
                   return true;
               }
               else{
                   return false;
               }
           }
           else{
               return false;
           }
       }
   }
       return false;
  
  
     
   }

   public static void main(String[] args) {
       int[][] A = {{0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
       int[][] B = {{1, 1, 1, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}};
       int[][] C = {{1, 1, 0, 1}, {1, 0, 1, 1}, {1, 0, 1, 1}, {0, 1, 1, 0}};
       if (isSymmetric(A)) {
   System.out.println("Symmetric");
       }
   else{
       System.out.println ( "Asymmetric");
   }
       if (isAntiSymmetric(A)){
           System.out.println(" Anti-Symmetric");
       }
       if (isReflexive(A)){
           System.out.println("Reflexive");
       }
       if (isSymmetric(B)) {
   System.out.println("Symmetric");
       }
   else{
       System.out.println ( "Asymmetric");
   }
       if (isAntiSymmetric(B)){
           System.out.println(" Anti-Symmetric");
       }
       if (isReflexive(B)){
           System.out.println("Reflexive");
       }
      
       if (isSymmetric(C)) {
   System.out.println("Symmetric");
       }
   else{
       System.out.println ( "Asymmetric");
   }
       if (isAntiSymmetric(C)){
           System.out.println(" Anti-Symmetric");
       }
       if (isReflexive(C)){
           System.out.println("Reflexive");
       }
  
      
      
   }
}

Add a comment
Know the answer?
Add Answer to:
In java please Program 5.1: Properties of a Relation Write a program that can determine which,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a MIPS program to that will take two 4x4 matrices, and calculate their sum and...

    Write a MIPS program to that will take two 4x4 matrices, and calculate their sum and product, using row major, and column major math (so this is actually 4 problems, but obviously they’re all pretty related). I generated two sample arrays to test 2   1       9       2 7   9       10      10 3   4       4       4 2   5       4       4 8 7 1 2 2 7 8 6 7 5 6 8 9 4 8 9 The output of your program...

  • Python 3 Discrete​ ​Mathematics We are going to write a program to read in relations, show...

    Python 3 Discrete​ ​Mathematics We are going to write a program to read in relations, show the matrix of the relation. We will also show if the relation is reflexive, symmetric, anti-symmetric and transitive. This program will read in files that the user gives. Normal Error handling applies. The file the user gives you will have the elements of the set for the relation followed by the tuples in the relation. The​ ​Text​ ​Files The first line of the text...

  • MUST BE PROCEDURAL CODE. Write a program in C++ that reads two matrices and: 1) adds...

    MUST BE PROCEDURAL CODE. Write a program in C++ that reads two matrices and: 1) adds them (if compatible) and prints their sum, 2) subtracts them (if compatible) and prints their difference, and 3) multiplies them (if compatible) and prints their product. Prompt the user for the names of two matrix input files (see format below) and place the output in a file of the user’s choosing. The format of the input files should contain the number of rows, followed...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

  • Question 4 (3 mark) : Write a Java program to ask the user to input an...

    Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should...

  • USE JAVA PLEASE And answer all questions Question 5.1 1. Write a program that reads in...

    USE JAVA PLEASE And answer all questions Question 5.1 1. Write a program that reads in a number n and then reads n strings. it then reads a string s from the user and gives you the word that was typed in after s. Example input: 4 Joe Steve John Mike Steve Example output: John Example input: 7 Up Down Left Right North South East Right Example output: North 2. Remember to call your class Program Question 5.2 1. Write...

  • In a sensible language ( any of C#/Java/Python) write a program which correctly calculates add, subtract,...

    In a sensible language ( any of C#/Java/Python) write a program which correctly calculates add, subtract, multiply and divide using our ‘minifloat’ binary format using an algorithm you code yourself.  Some details: Your program only needs to work on two ‘numbers’ at a time, read those in from a text file – failure to read those values from a text file will result in a grade of 0.   For each ‘number’ store the sign, exponent and mantissa separately.   You can hard code your...

  • (Java Please) Sum of Digits Write a program that will sum the digits of a number...

    (Java Please) Sum of Digits Write a program that will sum the digits of a number input by the user. For example, if the user enters the number 1234, the sum of the digits will be 10 (1 + 2 + 3 + 4 = 10). The user will enter a number with at least 4 digits (greater than 1000). That value will be sent to a method which will return the sum. Sample Output 1: SUM OF DIGITS -------------...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT