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.

Quote:

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!

Re: Method return with Math.min

Well Math.min can only take two arguments, so you can try doing:

Code:

`int min = Math.min(i, j);`

min = Math.min(min, k);

:D

Re: Method return with Math.min

Thanks! Actually wouldn't had figured that out easily :D Edit: Confirmed working

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.