Answer to Question #293485 in Java | JSP | JSF for Bonnie

Question #293485

Can you change the code into java code?




def reflexive(R):



'''



@param R : set containing homogenous elements



'''



result = []



a = []



y = []




for a1, a2 in R:



if (a1 == a2):



result.append((a1,a2))



y.append(a1)




if (a1 not in a):



a.append(a1) #contains list of a0




if (set(a) == set(y)):



print("Reflexive")



return (result, True)




print("Not Reflexive")



return ([] , False)

1
Expert's answer
2022-02-03T03:59:44-0500
import java.util.LinkedList;

public class Main {
    public static boolean isReflexive(LinkedList<Integer> set, LinkedList<int[]> relations) {
        for (Integer element : set) {
            boolean exist = false;
            for (int[] relation : relations) {
                if (relation[0] == element && relation[1] == element) {
                    exist = true;
                    break;
                }
            }
            if (!exist) {
                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