inline if statement java, why is not working

if-statement, inline, java

Solution

The ternary operator `? :` is to return a value, don't use it when you want to use `if` for flow control.

if (compareChar(curChar, toChar("0"))) getButtons().get(i).setText("§");

would work good enough.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

Problem

Desc: compareChar returns true or false. if true it sets the value of button, if false do nothing. I am trying to use: ``` if compareChar(curChar, toChar("0")) ? getButtons().get(i).setText("§"); ``` netbeans is saying: ')' excepted ':' excepted I tried these combinations: ``` if compareChar(curChar, toChar("0")) ? getButtons().get(i).setText("§"); if compareChar(curChar, toChar("0")) ? getButtons().get(i).setText("§") : ; if compareChar(curChar, toChar("0")) ? getButtons().get(i).setText("§") : if (compareChar(curChar, toChar("0"))) ? getButtons().get(i).setText("§"); if (compareChar(curChar, toChar("0"))) ? getButtons().get(i).setText("§") : ; if (compareChar(curChar, toChar("0"))) ? getButtons().get(i).setText("§") : ```

Original source