Minimum of two numbers

  • 7
Someone is younger, someone else is older. Someone is taller, someone else is shorter. In programming, searching for smaller and larger values is just as important as in the real world. Of course, programming is the real world, right? Let's write a method that compares two integers and returns the minimum.
You can't complete this task, because you're not signed in.
Comments(32)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
JakubLevel 10 , Ostrava
27 May, 18:47
For those who wonder if there are some other ways how to solve this task (instead of "if") - then in 5 level, lesson 10 there is a link to this article about "Ternary operators" which can help you to solve the task only with one line: https://codegym.cc/groups/posts/14-ternary-operator
KingBiggieLevel 6 , Bodegraven
15 April, 12:46
I'd like to have a proper response to it being equal. However it won't accept returning a string or null in such a case. What else can I use? A random number or the sum of the numbers works but isn't a great solution.
ROBORUDYLevel 2 , Milwaukee
13 March, 17:57
Copied from CodeGym user Kermit Stanbach: "If this helps anyone (maybe I'm just saying this to reinforce the idea for myself). But return statements can not be within the "if" block (field), and you can only have one return statement. " An eye opener. It reminded me of the previous page for calling methods. I studied the code and was able to implement the code. This lesson does feel out place and out our skill ability, but part of the beauty of coding is being creative in finding resources to finding answers. The difficulty really hones in that idea. The course does not disappoint. The lessons push you to your limits of understanding and make that feeling of accomplishment that much sweeter.
Kermit StanbachLevel 3 , Redstone Arsenal
4 January, 17:26
If this helps anyone (maybe I'm just saying this to reinforce the idea for myself). But return statements can not be within the "if" block (field), and you can only have one return statement.
Cameron MayorLevel 3 , Washington
2 January, 01:10
What if the 2 numbers are equal? This does not occur in the 3 given examples, but would be good to call out early on like this to reinforce the need to account for all possible scenarios when writing functions. Thanks!
Willard RoseberryLevel 11 , Brigham City
16 November 2019, 15:12
I had to make a local variable in the method to compare the other variables being passed to the method. That was the hardest part to figure out for me.
GoffLevel 8 , Berlin
6 October 2019, 22:33
Hint - google for ternary operators and use it in return statement ;)
Chotan BaruaLevel 7 , New York City
1 October 2019, 20:55
What i am doing wrong ?
int a = -10;
       int b = -20;
       int min;
       ...
RomanLevel 41
2 October 2019, 06:11
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
JeffLevel 6 , Taco Town
25 June 2019, 15:01
You call the smallest number from each argument in the main method
GáborLevel 14 , Budapest
24 June 2019, 19:19
/* Comment has been deleted */
RomanLevel 41
25 June 2019, 05:28
Posting the solution in the comments is prohibited.