Question
need help with what is wrong with my code? import java.io.File; import java.io.FileNotFoundException; // Import this class to handle errors import java.util.Scanner; class Relation {
need help with what is wrong with my code?
import java.io.File;
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner;
class Relation {
// This method returns if matrixrix is reflexive or not
public static Boolean isReflexive(int matrix[][],int n){
for(int i=0;i if(matrix[i][i]!=1) return false; } return true; } // This method returns if matrixrix is antireflexive or not public static Boolean isAntiReflexive(int matrix[][],int n){ for(int i=0;i if(matrix[i][i]!=0) return false; } return true; } // This method returns if matrixrix is symmetric or not public static Boolean isSymmetric(int matrix[][],int n){ for(int i=0;i for(int j=0;j if(i==j) continue; if(matrix[i][j]!=matrix[j][i]) return false; } } return true; } // This method returns if matrixrix is antisymmetric or not public static Boolean isAntiSymmetric(int matrix[][],int n){ for(int i=0;i for(int j=0;j if(i==j) continue; if(matrix[i][j]==matrix[j][i]) return false; } } return true; } public static void main(String[] args) { // Reading file name from user System.out.print("File input: "); Scanner sc = new Scanner(System.in); String file_name = sc.nextLine(); sc.close(); // try to open and read file try { File myObj = new File(file_name); Scanner user = new Scanner(myObj); int matrix[][] = new int[10][10]; int i=0; // reading the file and filling matrix while (user.hasNextLine()) { String data = user.nextLine(); for(int j=0;j matrix[i][j] = Integer.parseInt(data.split(" ")[j]); } i++; } // Displaying all the output System.out.println("Reflexive - " + (isReflexive(matrix, 10) ? "yes" : "no")); System.out.println("AntiReflexive - " + (isAntiReflexive(matrix, 10) ? "yes" : "no")); System.out.println("Symmetric - " + (isSymmetric(matrix, 10) ? "yes" : "no")); System.out.println("Antisymmetric - " + (isAntiSymmetric(matrix, 10) ? "yes" : "no")); user.close(); } catch (FileNotFoundException e) { // if error occurred while opening the file System.out.println("An error occurred."); e.printStackTrace(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started