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.
Minimum of two numbers
- 7
Locked
Comments (46)
- Popular
- New
- Old
You must be signed in to leave a comment
Protsky
10 December 2021, 13:37
if a = b ? Maybe rewrite the description of the problem
0
Víctor Alfonso Martínez Gómez
10 August 2021, 22:05
Estructura condicional if.
if ( ) {
////;
}
else
{
/////;
}
+1
David Cáceres
10 August 2021, 08:46
i like how the concepts go slowly pilling up, fun way to remember the things you learnt before.
0
Paul.ATX
25 July 2021, 17:34
I don't recall going over the if/else training yet, is that required for this?
+1
Toka
8 July 2021, 21:03
Hi, I solve task with simple Math.min() method. :)
0
hidden #10757948
18 June 2021, 08:36
Create int variable using Math.min function for (a, b)...Then do simple if/else statement for variable output e.g. variable name = a else variable name = b...Then return that variable name...
+1
Rica
16 April 2021, 01:02
How does the second method know that there is a a and b. Does Java just assume when you say "a >b" that you are looking at two different given numbers?
0
Eros nullfeathers
22 March 2021, 05:05
So why is there now curly brace after the if statement. A book im looking into along this site has curly braces after each if and else, etc. Is it because it is inside a method ?
0
Roman
22 March 2021, 07:03
In the case of using one statement, curly braces can be put or not put.
If you want to group more than one statement in the if block then you have to use curly braces.
+4
EugeneEmory
2 March 2021, 17:22
for anyone new, there is a method built into java that finds the min/max of numbers. Go to w3 code school and read the Java Math section
0
Seth Barker
3 January 2021, 20:38
So during the lesson portion, I was so bamboozled by there not being a semi-colon after the if line. Turns out, the semi-colon signifies the end of the line of complete, ready to execute, code. If the if line contained that semi-colon, it wouldn't know what to compare to.
+1