利用if...else語句,這是最普通的做法
public class Three62 {
public static void main(String[] args) {
int i=120,j=119,k=110;
int max;
if(i>j)
max=i;
else
max=j;
if(max>k)
System.out.println(max);
else
System.out.println(k);
}
}
這種方法利用了三目運算符“?:”,表達式瞬間提高了一個逼格,而且看起來簡潔易懂
public class Three62 {
public static void main(String[] args) {
int i=120,j=119,k=110;
int max;
max = (i>j)?i:j;
max = (max>k)?max:k;
System.out.println(max);
}
}