• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boolean Arrays, Scanners and If Statements

 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a program in java that will play tictactoe against you. I am currently working on the Human's turn, where you input the number of the square you would like. No matter what square I choose it says it is already choose. I am using a boolean array to tell whether the squares are empty or not, false = empty and true = taken. I can not figure out what the problem is. Any suggestions or advice would be greatly appreciated.

Here is the Instance Data:


And here is the Method:
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think this does:
 
Mike Simmons
Ranch Hand
Posts: 3076
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(deleted so as to not spoil Kemal's question)
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh it should be

instead? Otherwise it would automatically go to that one instead of the other ones?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was that an answer or a question?

As in previous topic, we have a problem with operators again. Now can you say the difference between = and == operator?
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question. We were always told that an '=' wouldnt work, and that you should always use an '=='.
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Hammersmith wrote:A question. We were always told that an '=' wouldnt work, and that you should always use an '=='.



Well, obviously, this isn't true -- as you found a case where it compiles. But back to the previous question -- do you know the difference between the two operators? and their usage?

Henry
 
Andy Hammersmith
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that '==' mean its going to be exactly equal too.
But, I dont know what just one means.
 
Henry Wong
author
Marshal
Pie
Posts: 21115
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Hammersmith wrote:I know that '==' mean its going to be exactly equal too.
But, I dont know what just one means.


Look at the rest of you program. Are there places where you are using a single equals ? Well, it does the same thing as the single equals in those other places.

Henry
 
Mike Simmons
Ranch Hand
Posts: 3076
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Hammersmith wrote:A question. We were always told that an '=' wouldnt work, and that you should always use an '=='.

I guess it depends what was meant by "wouldn't work". Most of the time it won't compile at all. Occasionally it will compile, but not do what you want it to. Both can be considered examples of "not working". In either case, you should always use '=='.

Unless, of course, you specifically want to assign a value to a variable, or to an array element. For that, use '='. For everything else, use '=='.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Hammersmith wrote:Oh it should be
. . .
No. You should never use == true or == false or similar. You should write what follows first if you want it true, and what follows second for false.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic