Hi,
i need to solve this problem:
private String enterMoveIntoColPosition(String row, int colNum, String playerSymbol)
This method has three parameters, a String representing one row of the TicTacToe game (6 characters
in length, e.g., "X – O "), the column number (1, 2 or 3), and the player symbol (either "X" or "O").
The player symbol is inserted into the correct position of the row and the resulting String is returned by the method
The followig code was provided:
private String enterMoveIntoColPosition(String row, int colNum, String playerSymbol) {
String col1, col2, col3;
any help would be much appreciated!
Thanks
Help in programming a game of tic tac toe
Started by Stilmatz, Jan 19 2010 03:02 PM
1 reply to this topic
#1
Posted 19 January 2010 - 03:02 PM
|
|
|
#2
Posted 19 January 2010 - 03:52 PM
I'd probably use chars instead of Strings, but it sounds like that's not your call. Anyway, it looks like you have to use substrings to take the parts of "row" that won't change, and stick your new playerSymbol in it - resulting in a new string.
So if colNum = 2, you need to take the first 2 letters of row (symbol and a space), add the player symbol, then add the final three letters of row (space, symbol, space).
So if colNum = 2, you need to take the first 2 letters of row (symbol and a space), add the player symbol, then add the final three letters of row (space, symbol, space).
private String enterMoveIntoColPosition(String row, int colNum, String playerSymbol) {
if (colNum == 2) {
return row.substring(0,2) + playerSymbol + row.substring(3,6);
}
// fill in the rest ;)
}


Sign In
Create Account

Back to top









