Minimum of two numbers

  • 7
  • Locked
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 (46)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Protsky
Level 7 , Switzerland
10 December 2021, 13:37
if a = b ? Maybe rewrite the description of the problem
Víctor Alfonso Martínez Gómez
Level 3 , Manizales, Colombia
10 August 2021, 22:05
Estructura condicional if. if ( ) { ////; } else { /////; }
10 August 2021, 08:46
i like how the concepts go slowly pilling up, fun way to remember the things you learnt before.
Paul.ATX
Level 3 , Austin, United States
25 July 2021, 17:34
I don't recall going over the if/else training yet, is that required for this?
Toka
Level 11 , Dugo Selo, Croatia
8 July 2021, 21:03
Hi, I solve task with simple Math.min() method. :)
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...
Rica
Level 3 , Manchester, United States
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?
Eros nullfeathers
Level 4 , Salt Lake City, United States
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 ?
Roman
Level 41
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.
EugeneEmory
Level 8 , San Antonio, United States
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
Seth Barker
Level 5 , Eureka Springs, United States
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.