D.4. Declaring Methods with Multiple Parameters
We now consider how to write your own methods with multiple parameters. Figure D.2 uses a method called maximum
to determine and return the largest of three double
values. In main
, lines 14–18 prompt the user to enter three double
values, then read them from the user. Line 21 calls method maximum
(declared in lines 28–41) to determine the largest of the three values it receives as arguments. When method maximum
returns the result to line 21, the program assigns maximum
’s return value to local variable result
. Then line 24 outputs the maximum value. At the end of this section, we’ll discuss the use of operator + in line 24.
1 // Fig. D.2: MaximumFinder.java 2 ...
Get Android™ How to Program, Second 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.