File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Boolean Arrays, Scanners and If Statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Boolean Arrays, Scanners and If Statements" Watch "Boolean Arrays, Scanners and If Statements" New topic
Author

Boolean Arrays, Scanners and If Statements

Andy Hammersmith
Greenhorn

Joined: Sep 30, 2012
Posts: 13
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

Joined: Jun 19, 2010
Posts: 825
    
    5

What do you think this does:


The quieter you are, the more you are able to hear.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2969
    
    9
(deleted so as to not spoil Kemal's question)
Andy Hammersmith
Greenhorn

Joined: Sep 30, 2012
Posts: 13
Oh it should be

instead? Otherwise it would automatically go to that one instead of the other ones?
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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

Joined: Sep 30, 2012
Posts: 13
A question. We were always told that an '=' wouldnt work, and that you should always use an '=='.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Andy Hammersmith
Greenhorn

Joined: Sep 30, 2012
Posts: 13
I know that '==' mean its going to be exactly equal too.
But, I dont know what just one means.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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

Joined: Mar 05, 2008
Posts: 2969
    
    9
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

Joined: Oct 13, 2005
Posts: 36501
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Boolean Arrays, Scanners and If Statements
 
Similar Threads
Array without ints
cleaner code
array of array help
Scanners put into if statements
reading input from a file into a array