The min()
function returns the smallest value among the two numbers
sent as a parameter.
Figure 1 shows a visual representation of the min()
function.
type min(type num-1, type num-2)
The min()
function takes two numbers as a parameter.
The numbers can be
int
,double
,float
, orlong
.
The min()
function returns the smallest value from the two numbers sent as a parameter.
class JAVA {public static void main( String args[] ) {// two positive numbersSystem.out.println("Minimum between 9 and 8:");System.out.println(Math.min(9,8));//one positive and the other negativeSystem.out.println("Minimum between -9 and 8:");System.out.println(Math.min(-9,8));// both negative numbersSystem.out.println("Minimum between -9 and -10:");System.out.println(Math.min(-9,-10));// both double numbersSystem.out.println("Minimum between 12.234 and 1.2345:");System.out.println(Math.min(12.234,1.2345));// one int and the other doubleSystem.out.println("Minimum between 12.234 and 1:");System.out.println(Math.min(12.234,1));}}