... same algorithm that we used in Section 5.4 to determine the largest of its three arguments. The method assumes that its first argument (x) is the largest and assigns it to local variable max (line 16 of Fig. 20.5). Next, the if statement at lines 18–20 determines whether y is greater than max. The condition invokes y’s compareTo method with the expression y.compareTo(max), which returns a negative integer, 0 or a positive integer, to determine y’s relationship to max. If the return value of the compareTo is greater than 0, then y is greater and is assigned to variable max. Similarly, the if statement at lines 22–24 determines whether z is greater than max and, if so, assigns z to max. Then line 26 returns max to the caller.

Calling Method maximum ...

Get Java How To Program, Late Objects, 11th Edition 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.