#Changing 1 value of an array changes every value after.
1 messages ยท Page 1 of 1 (latest)
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
ue in the array instead of just the one I want to change. Can someone please help me troubleshoot this issue?
When you change one value in an array, especially if it is a multi-dimensional array like in a Tic Tac Toe game, it is important to understand how arrays work in Java. In Java, arrays are reference types, which means that when you assign an array to a new variable, you are actually creating a new reference to the same array in memory.
So when you change one value in the array, it will affect every reference to that same array. To avoid this issue, you can create a deep copy of the array before making any changes. This can be done using the clone() method or by manually iterating through the original array and copying each element to a new array.
Another approach is to make sure that you are only changing the specific value you want by ensuring that your code is correctly indexing into the array. Double-check your code to make sure that you are updating the correct index and not inadvertently changing other values in the process.
By understanding how arrays work in Java and being mindful of how you are accessing and updating values, you can prevent unintended changes to your array elements and fix the issue with your Tic Tac Toe game.
I uploaded your attachments as Gist.
Also, any other help, like seeing a flaw in my code and pointing it out is completely on the table! I'm new and trying to get better.
At the start the game looks like this:
-=-=-=-=-=-=-=-=-
1 | 2 | 3
---------
4 | 5 | 6
---------
7 | 8 | 9
-=-=-=-=-=-=-=-=-
or something a little better but it's in console so it looks bad when i send here
then when i write "1" it does this:
-=-=-=-=-=-=-=-=-
X | X | X
---------
X | X | X
---------
X | X | X
-=-=-=-=-=-=-=-=-
then, now it's "O" turn, and i say "5" it does this.
-=-=-=-=-=-=-=-=-
X | X | X
---------
X | O | O
---------
O | O | O
-=-=-=-=-=-=-=-=-
i forgot the break;
... i got it now, thanks 
I apologize but i do not know how to delete a post
If anyone sees this and wants to do a code review though, that would be nice
The project is still in progress though.