Hello, I have a tic tac toe board class, which will be used to instantiate board objects. I am kind of confused how to print out the character  vertically. I have done this before with using loops. Does the same approach need to be taken? Is there any methods on java api that will flip characters in an array for you? The reason I ask is bc I am having problems implementing this loop into my board class code. It say board[i] can not be dereferenced. I already have a char with a reference to this array called board. I don't know if this class works properly bc I can't get it to display the following; xox oxo *** something like that; so that the characters appear vertically. All I got with 3 system.out.print(board[i]) calls was the following *** or 3 system.out.println(board[i]) calls was * * * I have made a program that took a string and did this before, can I use that class in this board class program? well anyways I'll post my code for the board class. If anyone could please suggests something; i'll try anything. Thanks in advance.
Originally posted by Mike Smith: ... It say board[ i ] can not be dereferenced. I already have a char with a reference to this array called board...
Basically, the dot (.) operator "dereferences" a variable that holds a reference to an object. You might think of it as "getting" the object. This allows you to access an object member -- for example, a method or field...
But variables that hold primitive values cannot be dereferenced. There's no object to "get," and no "members" to access. That's the issue here: board is a char array, so char[x] represents a primitive char. Therefore, you can't dereference it with a call like char[x].nextChar().
(In your previous code, your array held object references instead of primitive values, so you could dereference with str[x].nextChar().)
Originally posted by Mike Smith: ... Is there any methods on java api that will flip characters in an array for you? ...
Not really. This is something you need to code.
For displaying the array, you basically need to print 3 chars per line. There are a variety of ways to do this, but here's a very straight-forward approach...
Note that there's no need to loop here, because the size of the board is pre-defined. Also note that I started each line with an empty String so that the + operator concatenates subsequent values as Strings, rather than adding them as values. [ November 09, 2005: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Sep 23, 2005
Hello, thanks for the reply. That idea never occurred to me. I always have a tendency of thinking more about a problem and skipping the simple tasks and jump right into the more complex ways of handling a problem. I got the board to print out. But now I am faced with a problem of updating the array. Although, thanks for the input; it is greatly apprecited.