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 (62)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
sugiharto Singodimejo
Level 8 , Jakarta, Indonesia
11 February, 21:33
i use chat gpt public static int min(int a, int b, int c, int d) { //write your code here int minab = min(a,b); int mincd = min(c,d); return min(minab,mincd); } public static int min(int a, int b) { //write your code here return a < b ? a : b;
Level 2 , United States of America
13 September 2021, 17:28
I am getting this error. can anyone help me please? com/codegym/task/task02/task0217/ error: unreachable statement return 0;
John Squirrels Website Admin at CodeGym
14 September 2021, 14:33
Please send us a DM.
Yusuf el Turki
Level 5 , Rhein, Germany
18 May 2021, 05:38
I got the correct output but i got these Warnung. I dont understand why is that so, What means same method? I have got 2 different if method wrote.
John Squirrels Website Admin at CodeGym
20 May 2021, 10:09
Yusuf, please create a question regarding this task in HELP section and send us a link. Our devs will be happy to assist you with the task.
Level 3
12 August 2021, 21:33
Create an object for your function. Int e= min(a,b); Then search for the smallest value And when your stuck check out the Community help functie.
Eros nullfeathers
Level 4 , Salt Lake City, United States
23 March 2021, 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.
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 ..
Level 8 , Malmö, 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.
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);

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

    public static int perimeterOfSquare(int side) {
        return 4 * side;
Output is the same, but ...
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?
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.
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 :)
Level 41
22 September 2020, 06:31
Because tests use different data
Shreedhar D Joshi
Level 3 , Mumbai, India
6 April 2020, 14:20
how can i solve this plz help