Answers for "can you use the ternary operator with multiple conditions java"

3

can you use the ternary operator with multiple conditions java

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";
Posted by: Guest on July-13-2020

Code answers related to "can you use the ternary operator with multiple conditions java"

Browse Popular Code Answers by Language