[Solved] Java logic operators [closed]


No, that would be a compilation error since it is parsing as

if ((clickedButton == button0) || (button1) || (button2) ...

and buttons are not booleans.

You must do:

if (clickedButton == button0 || clickedButton == button1 ...

But an array would be much cleaner, instead of having nine separate button variables. Then you could do this:

if (Arrays.asList(buttons).contains(clickedButton)) {
    ...
}

Or, if your buttons are stored in an ArrayList (or any List), it’s just

if (buttons.contains(clickedButton)) {
    ...
}

7

solved Java logic operators [closed]