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
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
English,
2 months ago
Science,
2 months ago
Social Sciences,
10 months ago
Science,
10 months ago
History,
10 months ago