I am trying to make couples out of an array of names (naam
). These couples need to be unique every time I run it. The case is a teacher trying to make couples for amountWeeks
weeks, the couples have to be unique from the other weeks and can't have Bob - Alice
and Alice - Bob
. If you haven't noticed, yes this is an assignment. I know your policy towards this, but I've been stuck on this for so long that even a push in the right direction would help a ton.
I have been doing it like this:
for (int n = 1; n < amountWeeks + 1; n++) {
Object[] x = {"WEEK", "<html><b>" + n + "</b></html>"};
model.addRow(x);
pos1 = 1;
pos2 = naam.size() - n;
for (int i = 0; i < naam.size() / 2; i++) {
Object[] row = {naam.get(pos1), naam.get(pos2)};
pos1++;
pos2 = pos2 - n;
if (pos2 == pos1) {
pos2 = pos2 - 1;
}
if (pos2 < (naam.size() - 1) / 2) {
pos2 = pos2 + (naam.size() - 1) / 2;
}
model.addRow(row);
}
}
But this produces doubles and as far as I know isn't the best way of doing this?