... same algorithm that we used in Section 6.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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access