© Ron Dai 2019
R. DaiLearn Java with Mathhttps://doi.org/10.1007/978-1-4842-5209-3_18

18. Conditional Statements

Ron Dai1 
(1)
Seattle, WA, USA
 

How do you identify and express the bigger number between the two numbers, x and y?

Math: Hypothesis and Conclusion

In a mathematical formula, we have to introduce the absolute sign to form an expression:

The bigger number between x and y ../images/485723_1_En_18_Chapter/485723_1_En_18_Figa_HTML.gif $$ \frac{\left(\mathbf{x}+\mathbf{y}\right)+\mid \mathbf{x}\hbox{--} \mathbf{y}\mid }{\mathbf{2}} $$

Recall the if/else structure:
if (x >= y) {
       // x is the bigger number
} else {
       // y is the bigger number
}

It is very straightforward and fairly easy to read!

The if/else ...

Get Learn Java with Math: Using Fun Projects and Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.