Your if
statements won’t work how you expect them to to. Let’s take an example to see why:
if(board = true & board != false)
This has a number of problems:
- You don’t need to explicitly compare to
true
andfalse
. Doing so is considered bad style.if (board)
is exactly equivalent toif (board == true)
. board = true
is assignment, not comparison. You actually have this mistake in several places. This is one of the main reasons yourif
statements aren’t working how you expect:if (board = true)
can’t possibly be false, so theelse
statement can’t possibly run. Check your code carefully for other cases where you’ve confused=
and==
(there are several).if (board == true && board != false)
is redundant and may represent a misunderstanding of howboolean
values work. If(board == true)
, then of courseboard != false
. Think about what it would mean ifboard == true && board == false
; under what conditions could something like this possibly be true? Keep in mind that, by definition,boolean
values are eithertrue
or false (but not both and certainly not some third value); there are only 2 possible choices.
I’d definitely encourage you to review how comparison works in Java as well as taking a look at this rather excellent article on debugging. You particularly want to focus on learning how and where to set breakpoints (i.e. points where the IDE will pause execution and allow you to examine your program’s state) and how to step through your code (i.e. run your program one line at a time so you can see the effect of each line of code) with a debugger.
1
solved How do you make a certain block of code run based on user input? [closed]