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
Post a Comment