Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

Daniel Bernardy

Greenhorn
+ Follow
since Dec 06, 2017
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Bernardy

I'm not entirely sure what is being asked here but from what I understand a 2d array is being made for the board and turn are taken to play tick tack toe in which case I think the problem will likely be located in how the board is read to determine if the game is over or not in which case I think there should be the first check if there are any vertical rows that are filled in for a win , then horizontal then vertical, and finally it should check if all the spaces are filled in. the first check should be a for loop inside a for loop checking if all the values in the collum are the same and if they are then it checks one to determine who wins, after that the same process for horizontal except its rows instead of columns and finally, for diagonal it will check the three locations for a diagonal line to see if they match and respond in the same manner as the previous two. the last check should be for if the entire board is filled in which case if all of the previous checks reveal there is no winner and the board has all spaces filled in then it should say that there is a tie if not then there could be a counter after that to add a value to a turn counter .All of these checks could be a method outside of the main method with a character value, three options for the first three methods being vertical horizontal and diagonal, two of the possible returns would be if one of the players win and the last possible char return for if there is no winner yet, and finally the last method that checks if the board is full should send out two possible char values one saying the board is full and the other that it is not full then a switch can be used to determine if there is a winner depending on the replys and at the end of it if the reply of the last method is full then it will say tie because there were no winners.
1 year ago
the only problem I see with your code is using == to compare strings in which case you should use .equals() instead to compare string values
1 year ago
Because .toUpperCase() only works with strings you could convert the char value ch to a string value with .toString() before using .toUpperCase() to convert it to upper case and after that, you can convert back to a char with .toChar()
1 year ago
because of the use of == on a string, it won't work and you should rather use .equals() for string values.
to help with the answer having uppercase letters you can add .toLower() to the end of the assigning of answer to make the string value all lower case letters, that way you don't have to worry about the user inputting uppercase or lower case values when comparing strings.
1 year ago
the difference between ++i and i++ is whether one is added to i before the statement is used in the case of ++i, or after the statement is done with i++

here is some example code with comments to better define whats happening:

1 year ago