/** * Function Name: checkColoumns * @param board * @return count (int) * Inside the function * -->will check every column for a straight X or straight O * -->The outer loop picks a column. The inner loop will index each row for that column. * */ public static int checkColoumns(char[][] board){ int count =0; for(int i=0; i<board.length; i++){ for(int j=0; j<board.length;j++){ if(board[j][i]=='X'){ count++; } else if(board[j][i]=='O'){ count--; } } if(count==3 || count ==-3){ return count; } else{ count =0; } } return count; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter