Sigur ca pare doar un mic amuzament sa rezolvi o problema de decizie cu operatorul ternar, singurul din tot limbajul care functioneaza cu trei operanzi. Uneori insa, in virtutea conciziei, o astfel de optiune este justificata, dupa cum este justificat, ba chiar preferabil, din considerente de eficienta, sa faci atribuirea:
int x = 0;
while(x <= 10) {x += 1;} in loc de "x = x + 1;"
intrucat in al doilea caz x este evaluat de doua ori.
Enuntul de pe programmr.com:
"Take input of experience and age of a person.
int x = 0;
while(x <= 10) {x += 1;} in loc de "x = x + 1;"
intrucat in al doilea caz x este evaluat de doua ori.
Enuntul de pe programmr.com:
"Take input of experience and age of a person.
If the person is experienced and his age is equal to or more than 35 the slary of the person is 6000. Otherwise, if the person is experienced and his age is equal to or more than 28 but less than 35, then the salary should be 4800.For experienced person below 28 yr of age the salary should be 3000 and for inexperienced person the salary should be 2000."