Getting Started with Java
This is a 100% free course, but we need you to first join or login to watch this video.
Alright, join or login here.Whenever you want to assign different values to a variable based on the outcome of an if else statement, a better approach is to use the ternary operator. It lets you write a condition followed by the value of the variable when the condition is true and the value of the variable when the condition is false.