Try this code... i didn't execute it but seems to be ok.
public Vector getTurns(String [] teams) {
Vector turns = new Vector();
fillTurns(teams, turns);
return turns;
}
public void fillTurns(String [] teams, Vector turns) {
for(int i = 0 ; i < teams.length ; i++) {
fillTurns(teams, teams [i], turns);
}
}
public void fillTurns(String [] teams, String currentTeam, Vector turns) {
for(int i = 0, j = 0 ; i < teams.length ; i++) {
if(!(teams [i].equals(currentTeam))) {
if(!(alreadyStored(teams [i], currentTeam, j, turns))) {
fillTurn(currentTeam, teams [i], turns, j);
}
j++;
}
}
}
private void fillTurn(String currentTeam, String aTeam, Vector turns, int j) {
Vector turn = (Vector) turns.elementAt(j);
if(turn == null) {
turn = new Vector();
}
turn.add(new String [] {currentTeam, aTeam});
}
private boolean alreadyStored(String aTeam, String currentTeam, int j, Vector turns) {
Vector turn = (Vector) turns.elementAt(j);
if(turn != null) {
for(int i = 0 ; i < turns.size() ; i++) {
String [] game = (String []) turns.elementAt(i);
if(game [0].equals(currentTeam) || game [1].equals(currentTeam)) {
return true;
}
}
}
return false;
}
}
Here's something I posted a while back, modify to suit
import java.io.*;
class RoundRobin
{
String[] team;
public RoundRobin()
{
try
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of teams: ");
int number = Integer.parseInt(input.readLine());
input.close();
setTheTeams(number);
printTheMatches();
}
catch(Exception e){System.out.println(e.getMessage());}
System.exit(0);
}
public void setTheTeams(int numberOfTeams)
{
int marker = 0;
if(numberOfTeams % 2 == 1) marker++;
team = new String[numberOfTeams + marker];
if(marker > 0) team[0] = " Bye ";
for(int x = 0; x < team.length-marker; x++) team[x+marker] = "Team"+(x+1);
}
public void printTheMatches()
{
int matches = team.length-1;
String temp = "";
for(int x = 0; x < matches; x++)
{
System.out.println("\nRound "+(x+1)+"...");
for(int y = 0, z = matches; y < (matches+1)/2; y++,z--)
{
System.out.println(team[y]+" vs "+team[z]);
}
temp = team[matches];
for(int z = matches; z > 1; z--) team[z] = team[z-1];
team[1] = temp;
}
}
public static void main(String[] args){new RoundRobin();}
}