Create your account

Already have an account? Login here

Note: By joining, you will receive periodic emails from Coursetro. You can unsubscribe from these emails.

Create account

24. Ternary Operator Example

Getting Started with Java

Woah, wait a second..

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.

Course Cirriculum