The ? Operator
Java involves a special ternary operator which can exchange certain types of if-then-else statements. That operator is the? and it works in java as like it does in C and C++ language. The operator can seem somewhat confusing at first, but the? Can be used extremely effectively once mastered. The? has this common form:
expression1? expression1: expression2
Here, expression1 could be any expression which evaluates to a boolean value. expression2 evaluated if expression1 is true; or else, expression3 is evaluated. The conclusion of the ? Operation is in which of the expression evaluated. Expression2 and expression3 both are required to return the similar type, that can't be void.
Here is an instance of the way that the? is employed:
ratio = denom == 0 ? 0 : num/denom;