# Thread: Method return with Math.min

1. Member
Join Date
Oct 2012
Posts
29
Rep Power
0

## Method return with Math.min

I'm doing selfchecks from my Java learning book.
In one of them, I'm told to do the following:
Write a method called min that takes three integers as parameters and returns the smallest of the three values; for example, a call of min(3, -2, 7) would return -2. Use Math.min to write your solution.

public class SelfCheck_3_12 {
public static void main(String[] args) {
int i = 10;
int j = 20;
int k = 30;
int minimum;
minimum = method(i, j, k);
System.out.println("minimum is = " + minimum);

}
public static int method(int i, int j, int k) {
int min = Math.min(i, j, k);
return min;
}

}
Something is wrong with the "int min = Math.min(i, j, k); it seems.
Anyone care to explain for me? Thanks!

2. Senior Member
Join Date
May 2012
Posts
172
Rep Power
9

## Re: Method return with Math.min

Well Math.min can only take two arguments, so you can try doing:
Java Code:
int min = Math.min(i, j);
min = Math.min(min, k);
:D

3. Member
Join Date
Oct 2012
Posts
29
Rep Power
0

## Re: Method return with Math.min

Thanks! Actually wouldn't had figured that out easily :D Edit: Confirmed working
Last edited by LasseA; 10-18-2012 at 11:21 PM.

4. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
19

## Re: Method return with Math.min

If the compiler complains (often with a "can't find symbol") the second thing to check is the API documentation which will tell you the number and types of arguments. This documentation should be open in your browser whenever you code. (Faith based programming just doesn't work)

The first is typos.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•