Computer Science, asked by liza1050, 1 month ago

Rewrite the given expression: boolean flag =(x>0)?1:0 using if...else statement.​

Answers

Answered by BrainlyProgrammer
3

Answer:

Your question has some mistakes.

boolean flag=(x>0)?1:0;

Error: int cannot be converted to boolean

Correct statement:-

  • boolean flag=(x>0)?true:false;

Conversion to if-else...

boolean flag;

if(x>0)

flag=true;

else

flage=false;

Syntax of Ternary operator:-

<data type><variable_name> = <condition>? <statement 1>:<statement 2>;

Syntax of if-else:-

if(condition)

statement 1;

else

statement 2;

Similar questions