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)
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;
}
}
Comments
Leave a comment