public static int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
return (x < y) ? -1 : ((x == y) ? 0 : 1);
3個條件的三元表達式:
((x == y) ? 0 : 1) 這裏面又是一個三元表達式 (x == y) ? 0 : 1
if (x < y) {
return -1;
} else if (x = y) {
return 0;
} else {
return 1;
}