public int findDIR(int col, int row, String word){ int DIR = 0; if(puzzle[(row+1+puzzle.length)%puzzle.length][col]==word.charAt(1)){ DIR = 1; } if(puzzle[(row-1+puzzle.length)%puzzle.length][col]==word.charAt(1)){ DIR = 2; } if(puzzle[row][(col+1+puzzle.length)%puzzle.length]==word.charAt(1)){ DIR = 3; } if(puzzle[row][(col-puzzle.length)%puzzle.length]==word.charAt(1)){ DIR = 4; } if(puzzle[(row+1+puzzle.length)%puzzle.length][(col+1+puzzle.length)%puzzle.length]==word.charAt(1)){ DIR = 5; } if(puzzle[(row+1+puzzle.length)%puzzle.length][(col-1+puzzle.length)%puzzle.length]==word.charAt(1)){ DIR = 6; } if(puzzle[(row-1+puzzle.length)%puzzle.length][(col-1+puzzle.length)%puzzle.length]==word.charAt(1)){ DIR = 7; } if(puzzle[(row-1+puzzle.length)%puzzle.length][(col+1+puzzle.length)%puzzle.length]==word.charAt(1)){ DIR = 8; } return DIR; } int count = 0; int DIR = 0; int incrow = 0; int inccol = 0; int i = 0; int j = 0; boolean foundStart = false; while(i < puzzle.length && j < puzzle.length && foundStart != true){ if(puzzle[i][j] == word.charAt(0)){ foundStart = true; DIR = findDIR(i, j, word); switch (DIR) { case 0: break; case 1: incrow = 1; break; case 2: incrow = -1; break; case 3: inccol = 1; break; case 4: inccol = -1; break; case 5: incrow = 1; inccol = 1; break; case 6: incrow = 1; inccol = -1; break; case 7: incrow = -1; inccol = -1; break; case 8: incrow = -1; inccol = 1; break; while(i < length){ rEturn[i] = puzzle[row][col]; row = (row+incRow+puzzle.length)%puzzle.length; //System.out.println("getPossible("+Row+" , "+Col+" , "+length+" , "+incRow+" , "+incCol+") row: "+row); col = (col+incCol+puzzle.length)%puzzle.length; //System.out.println("getPossible("+Row+" , "+Col+" , "+length+" , "+incRow+" , "+incCol+") col: "+col); //System.out.println("getPossible("+Row+" , "+Col+" , "+length+" , "+incRow+" , "+incCol+") word: "+rEturn[i]); i++; } String out = new String(); for(int j = 0; j < length; j++){ out += rEturn[j]; }