java - Compere if statement short form -


ı want use short form if statement. how can ı write if statement @ one line? , how can ı compare them ı know there same question @ here. statement not have else ı not without else statement.

public int compareto(uyum u) {             if (uyum < u.uyum)                 return -1;             if (uyum > u.uyum)                 return 1;             return 0;         } 

you can use ternary operator :

 return uyum < u.uyum ? -1        : uyum > u.uyum ? 1        : 0; 

Comments

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -