Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inline if statement java, why is not working

Tags:

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("§") : 
like image 385
Erik Kubica Avatar asked Mar 17 '13 12:03

Erik Kubica


People also ask

Why if-else is not working in Java?

Try putting {} around all the if statements and try running it again. I may be incorrect though. Although it does look like it's an if-statement scoping issue, indentation is not a part of it; Java does not care about whitespace like Python. However, proper bracing probably would fix the issue.

Why if-else is not working?

If you are getting an error about the else it is because you've told the interpreter that the ; was the end of your if statement so when it finds the else a few lines later it starts complaining. A few examples of where not to put a semicolon: if (age < 18); if ( 9 > 10 ); if ("Yogi Bear". length < 3); if ("Jon".

Why is Java skipping my IF statement?

The if statement is skipped because you have a bug and you don't yet fully understand what you're doing. That's normal for a newbie. Learn how to debug by using your IDE's facilities and using println statements. You'll get it if you work at it.

How if condition works in Java?

Java has the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true. Use else to specify a block of code to be executed, if the same condition is false. Use else if to specify a new condition to test, if the first condition is false.


1 Answers

Syntax is Shown below:

"your condition"? "step if true":"step if condition fails"
like image 166
Sachin Avatar answered Nov 01 '22 18:11

Sachin