Home / Java Tips Generated By ChatGPT / Ternary Operator in Java The ternary operator is a shorthand for if-else statements that assign a value based on a condition. Source Code int score = 75; String grade = score > 60 ? "Pass" : "Fail"; System.out.println(grade);