check row
Sat May 20 2023 14:50:52 GMT+0000 (Coordinated Universal Time)
Saved by
@gokulz
/**
* Function Name: CheckRows
*
* @param board
* @return count (int)
*
* Inside the function
* --> will check every row for a straight X or straight O
* --> The outer loop must run through each row while the inner loop runs through every character in that row.
* --> In each row, add 1 to count if there's an X. Subtract 1 if there's an O.
*/
public static int checkRows(char[][] board){
int count =0;
for(int i=0; i<board.length; i++){
for(int j=0; j<board[i].length; j++){
if(board[i][j]=='X'){
count++;
}
else if(board[i][j]=='O'){
count--;
}
}
if(count==3 || count == -3){
return count;
}
else{
count =0;
}
}
return count;
}
content_copyCOPY
Comments