Created by
Vambo Põldra
last modified
|
public class RoundRobin {
public static void main(String[] args) {
int n = 8;
int half = (n / 2 - 1);
for (int i = 1; i < n; i++) {
System.out.println("====Round " + i);
if (i % 2 == 0) {
createTeam(n, i);
} else {
createTeam(i, n);
}
for (int j = 1; j <= half; j++) {
int x = normalize(i + j, n - 1);
int y = normalize(i - j, n - 1);
if (x == 0) {
x = n - 1;
}
if (y == 0) {
y = n - 1;
}
if (j % 2 == 0) {
createTeam(y, x);
} else {
createTeam(x, y);
}
}
}
}
private static void createTeam(int home, int away) {
System.out.println(home + " : " + away);
}
private static int normalize(int x, int modulo) {
return (x % modulo + modulo) % modulo;
}
}
|