Results 1 to 4 of 4
Thread: Method return with Math.min
 10182012, 11:06 PM #1Member
 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;
}
}
Anyone care to explain for me? Thanks!
 10182012, 11:16 PM #2Senior 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);
WARNING I am Russian so it's possible that I wont understand you correctly...
 10182012, 11:19 PM #3Member
 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; 10182012 at 11:21 PM.
 10192012, 01:30 AM #4Moderator
 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.
Similar Threads

Cannot return Method's value
By darshanaprasad in forum New To JavaReplies: 2Last Post: 09082012, 08:25 AM 
Math.random() method problem
By katiebear128 in forum New To JavaReplies: 3Last Post: 10122011, 04:50 AM 
Using the Math.ceil method
By Allspark in forum New To JavaReplies: 8Last Post: 09102010, 05:52 AM 
Not able to return the method value
By dmakshay2002 in forum Advanced JavaReplies: 11Last Post: 05282010, 02:07 PM 
beginner grade 11need help with a math code involving returning values from a method
By bobmasta5 in forum New To JavaReplies: 3Last Post: 12102008, 01:38 AM
Bookmarks