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...
Hi Mike,
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...
myObjectRef.myMethod();
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...
System.out.println("" + board[0] + board[1] + board[2]);
System.out.println("" + board[3] + board[4] + board[5]);
System.out.println("" + board[6] + board[7] + board[8]);
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 ]