Minimum of four numbers

  • 7
  • Locked
Four tired cowboys sat in a room. Each of them has to draw a number out of a pot. Whoever of the four draws the smallest number has to go fetch some whiskey. Help these guys determine who has to go. Find the minimum of the four numbers.
You can't complete this task, because you're not signed in.
Comments (54)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Eros nullfeathers
Level 4, Salt Lake City, United States
23 March, 05:10
I just had an observation. Since the methods are public and using the same int a, b and for the other method c and d; Does it mean it is using the same variable if we use the 2 variable method inside the 4 variable method? Its obvious that yest this is true but I just wanted someone to confirm my "theory". I think this is a true observation as the methods are public and therefore able to share the 2 variables amongst each other.
Java_Mooood
Level 3, San Antonio, United States
16 October 2020, 17:34
It easy , -use the previous task(Minimum of three numbers ) -Call min(a,b) from the min(int a, int b, int c, int d) method to fix the overloading error that Intellj might display . -use if and if esle , else ..
vigvu
Level 6, Malmoe, Sweden
7 October 2020, 15:09
I had completed all the requirements in my program except for "The min(a, b, c, d) method must use the min(a, b) method.". So I looked for help and found out to put in "int min1 = min(a,b);" in the "min(a,b,c,d)" function and it passed the requirements. I am not sure if it's the correct way of solving this task because I think they wanted me to actually use this line of code more.
Roman
Level 41
12 October 2020, 06:11
for example, you need to use the perimeterOfSquare method, which should calculate the perimeter of a square. Correct version:
public class Solution {
    public static void main(String[] args) {
        int perimeter = perimeterOfSquare(2);
        System.out.println(perimeter);
    }

    public static int perimeterOfSquare(int side) {
        return 4 * side;
    }
}
Wrong version:
public class Solution {
    public static void main(String[] args) {
        int perimeter = perimeterOfSquare(2);
        System.out.println(4*2);
    }

    public static int perimeterOfSquare(int side) {
        return 4 * side;
    }
}
Output is the same, but ...
Sebastian
Level 3, Accra, Ghana
29 September 2020, 15:53
Help please, the result seem to give me the minimum of all the numbers but i can't pass the test. any help pls?
Roman
Level 41
2 October 2020, 06:03
Please post your question with the attached solution in the section Help.
Lorenzo Cammerinesi
Level 7, London, United Kingdom
22 September 2020, 08:10
Quite frustrated I found this task really easy, I solved it in three different ways on eclipse without problems instead here the task can't be accepted.In all 3 compilation I always respected what was requested and still I can't pass the task. I start to think that the program pretend exactly the writing that was saved in it so at this point is all about fortune to get it. I'm concern about the future tasks when stuff start to be harder.
Kasia
Level 22, Zabrze, Poland
18 September 2020, 11:00
Hi, I got the right output (the min number for each method) but the test failed on the last statement: The min(a, b, c, d) method must return the minimum of the numbers a, b, c, and d >.> If anybody could explain why that would be wonderful and very useful to me :)
Roman
Level 41
22 September 2020, 06:31
Because tests use different data
Sean Walker
Level 3, Manchester, United States
14 March 2020, 03:55
I'm stuck on this one... I've looked up alternative tutorials on overloading methods and I am still not getting how to put all the pieces together... does anyone got a good tutorial on overloading methods? I'm not looking for the answer to the task, I want to learn this and understand this.
olik09
Level 9, Riyadh, Saudi Arabia
3 April 2020, 07:20
Start with the second min function. The second function will return to you the min which is a or b and will print when it's called in the main function. For the first min, you need to call the second function to do the same thing for int a and b. You can do that by typing:
int whatever = min(a, b); \\ whatever is a variable, name it anything.
now "whatever" is the min of int a and int b. Now, use it to get the min of the three variables, "whatever", c and d. Then, let the function return to you the smallest of these and you're done.
HaeWon Chung
Level 17, Boston, United States
11 January 2020, 04:18
I think the real take home message of this task is that even if method names are same, java will consider them as different methods if the number of arguments (I guess types as well) are different.
Timothy Strong
Level 4, San Diego, United States
17 October 2019, 12:23
What does min(a,b,c,d) method use min(a,b) method mean?
Timothy Strong
Level 4, San Diego, United States
17 October 2019, 12:47
Got inside from fellow coder..thanks guyz!
Sacha
Level 3, Buchs, Italy
12 October 2019, 19:09
What is the meaning of calling the min function with two argumentes from the function with 4 argumentes?
18 December 2019, 12:37
You can compere a > b in the
min( a, b);
method and then store it in to a variable like this
int z = min(a, b)
and you can use to do stuff with it ( you will have somthing like 3 letters to compare instead of 4)
Brandon
Level 9, Toledo, United States
3 May 2020, 19:01
Could not remember how to use the answer out of min(a, b). Read this and was like OH DUH!
Rica
Level 2, Manchester, United States
20 April, 01:26
This helped me a lot. Thank you!