三元判斷式 判斷式?成立程式區塊:不成立程式區塊 三元判斷式 , 可以說是 if else 的簡寫版, 如果你的if else判斷是簡單的判斷, 可使用這三元判斷式, 多個if else if 判斷, 不建議使用三元判斷式, 因為會使程式複雜化。
// if()
score = 70;
if (score == 70) {// 條件成立 進入此程式區塊
System.out.println("條件成立 score:" + score);
}
else {// 條件不成立 進入此程式區塊
System.out.println("不條件成立 score:" + score);
}
//判斷式?成立程式區塊:不成立程式區塊
score = 70;
System.out.println(score == 70 ? "條件成立 score:" + score : "不條件成立 score:" + score);
文章標籤
全站熱搜
