📜  多个条件的三元运算符 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:11.890000             🧑  作者: Mango

代码示例3
String year = "senior";
if (credits < 30) {
  year = "freshman";
} else if (credits <= 59) {
  year = "sophomore";
} else if (credits <= 89) {
  year = "junior";
}
Contrast this with the ternary operator:

String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";