Computer Science, asked by HarshSingh0123, 5 months ago

Rewrite the following if statement by using ternary operator. [2] if(a<100) if(a<10) st=(“Single Digit”); else st=(“Double Digit”); else st=(“Multiple Digit”);

Answers

Answered by anindyaadhikari13
13

Question:-

  • Rewrite the following using ternary operator.

Solution:-

Given code,

if(a<100)

{

if(a<10)

st=(“Single Digit”);

else

st=(“Double Digit”);

}

else st=(“Multiple Digit”);

Using ternary operator, we can write like this,

st=(a<100)?((a<10)?"Single Digit":"Double Digit"):"Multiple Digit";

Similar questions