Home / Questions / Rewrite the following program segment using if-else statements instead of the ternary operator: String grade = (marks>=90)?"A": (marks>=80)? "B": "C";
Explanatory Question

Rewrite the following program segment using if-else statements instead of the ternary operator:

String grade = (marks>=90)?"A": (marks>=80)? "B": "C";

👁 61 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


String grade;
if (marks >= 90)
    grade = "A";
else if (marks >= 80)
    grade = "B";
else
    grade = "C";