By Tony Bevis on Tuesday, 10 October 2023
Category: Java

Java programming course: 5.8 The ternary operator

In the previous lesson you learnt about the if...else... block.

The ternary operator

There is a short-cut technique you can sometimes use in place of simple if...else... blocks. Consider the following code:

The ternary operator allows you to combine the comparison with the assignment thus: 

Enter your text here ...

The ternary operator consists of a number of parts:

In the next lesson you will learn about conditional statements using switch... case...:

Next lesson: 5.9 Conditionals using switch case

Related Posts

Leave Comments