Computer Applications
Explain Java function Math.min( ) with an example.
Input in Java
5 Likes
Answer
This function is used to return the minimum of two numbers. It returns an int value if both of its arguments are int otherwise it returns a double value.
Syntax
<Return data type><variable> = Function name (argument 1, argument 2);
double <variable> = Math.min(doubleArg1, doubleArg2);
int <variable> = Math.min(intArg1, intArg2);
For example, consider the statement
int n = Math.min(91, 89);
It will return the min value for n as 89.
The statement
double d = Math.min(52, 89.7);
will return a double type value for d as 52.0
Answered By
2 Likes