Answer to Question #293952 in Java | JSP | JSF for Bimbo

Question #293952

How to determine the set is symmetric using java code?


1
Expert's answer
2022-02-04T14:49:46-0500
import java.util.LinkedList;

public class Main {
    public static boolean isSymmetric(LinkedList<int[]> relations) {
        for (int[] relation : relations) {
            if (relation[0] != relation[1]) {
                boolean symmetric = false;
                for (int[] relationB : relations) {
                    if (relationB[0] == relation[1] && relationB[1] == relation[0]) {
                        symmetric = true;
                        break;
                    }
                }
                if (!symmetric) {
                    return false;
                }
            }
        }
        return true;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS