A common usage of
the conditional expression
- The conditional expression is
often used
to:
- Compute the
maximum
(or minimum) of
2 numbers
|
Example:
public class FindMaxMin
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double x, y, max, min;
x = input.nextDouble();
y = input.nextDouble();
max = (x > y) ? x : y;
min = (x < y) ? x : y;
}
}
|
|
DEMO:
demo/03-selections/09-cond-expr/FindMaxMin.java