Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String issues

807600Sep 3 2007 — edited Sep 3 2007
Hi. I am having some uses writing a class for one of my java courses. For this assignment I am supposed to create a class that accepts a string array of three elements that are supposed to be three characters long.

I'm running into several issues with my for loops and String variables that I define and I was hoping if someone would be able to help me with it. Here is a snippet of my code that basically has all of the errors I am running into:

//Test for vertical victory
for(int j=0; j<3; j++)
{
String tictac1 = board[1].charAt(j) + board[2].charAt(j) +board[3].charAt(j);
if((tictac1.compareTo("XXX") > 0) || (tictac1.compareTo("OOO") > 0))
answer = "Player " + board[1].charAt(j) + " won vertically at row " + j;
return answer;
}

The string array that I am using in this class I am creating is called board. I created tictac1 to try to concatenate the parts of the array I want to do a vertical test with. However I get an error that says:
...TicTacToe.java:36: incompatible types
found : int
required: java.lang.String
String tictac1 = board[1].charAt(j) + board[2].charAt(j) + board[3].charAt(j);

I then try to compare tictac1 to see if it is all Xs or all Os. This of course runs into another error:
...TicTacToe.java:43: cannot find symbol
symbol : variable j
location: class TicTacToe
String tictac2 = board[1].charAt(1) + board[2].charAt(2) +board[3].charAt(j);

Can anyone tell me of an alternate way of doing this?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 1 2007
Added on Sep 3 2007
2 comments
174 views